-
Exporting x,y,z corrdinates
Mahir Abrahim Jan 22, 2009 7:41 AM (in response to Ed Morris)Look into using a Hole Table in a drawing. I don't use them, but I believe they will give you XY coordinates which you can export to a spreadsheet. Getting the Z coordinate may be not possible. -
Exporting x,y,z corrdinates
Tom Nicholson Jan 22, 2009 10:35 AM (in response to Ed Morris)I'd say it would be possible with a macro..
How to do it, I can't help with..-
Exporting x,y,z corrdinates
Ed Morris Jan 22, 2009 12:00 PM (in response to Tom Nicholson)The 'points' I am referring to are in the assembly. By Bolt pattern I mean I select the hole cylindrical surface and insert a 'point'. From this I select measure to obtain the x,y,z coordinates.
Yes, the coordinates are with reference to the assembly coordinate system.
I could not find a way to export the coordinates of each point to a file that I can manipulate. I need to use these in another program.
Any hints
Ed
-
-
Exporting x,y,z corrdinates
Josh Brady Jan 22, 2009 11:13 AM (in response to Ed Morris)What kind of points? Are they points in a sketch? Where is the sketch located? In the bolt itself, in a hole wizard pattern on the component the bolts are fixing? In a sketch in the assembly? You want X, Y, and Z with respect to the main assembly's coordinate system? -
Exporting x,y,z corrdinates
Josh Brady Jan 22, 2009 12:16 PM (in response to Ed Morris)Sorry, I'm still not sure exactly what you're doing. There are a lot of ways to "insert a point" in SolidWorks. Are the 'points' you are inserting part of a sketch, or are they reference geometry points (as inserted by Insert->Reference Geometry->Point...? If they are part of a sketch, is it a 2-d sketch or a 3-d sketch?-
Exporting x,y,z corrdinates
Ed Morris Jan 22, 2009 12:55 PM (in response to Josh Brady)Sorry for the lack of clarity. Yes, the points are from reference geometry(Insert->Reference Geometry->Point.
Hope that makes it clear.
Ed
-
-
Exporting x,y,z corrdinates
Josh Brady Jan 22, 2009 1:32 PM (in response to Ed Morris)In that case, this oughtta do it for you. It will output the coordinates of every reference point in the active document to an Excel file. If you need more decimal places, add zeroes into the "FMAT" constant at the top. The "SF" constant is a scale factor. The 1000 value is to convert meters (the underlying unit that SW actually works in) to millimeters. If you're looking for inches, use 1000/25.4.
Option Explicit
Const FMAT As String = "0.00"
Const SF As Double = 1000
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim Feature As SldWorks.Feature
Dim myRefPoint As SldWorks.RefPoint
Dim myMathPt As SldWorks.MathPoint
Dim ptData As Variant
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Const FirstRow As Long = 4
Const FirstCol As Long = 2
Dim CurRow As Long
Dim IDCol As Long
Dim Xcol As Long
Dim Ycol As Long
Dim Zcol As Long
Dim PtID As Variant
Dim i As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets("Sheet1")
CurRow = FirstRow
IDCol = FirstCol
Xcol = FirstCol + 1
Ycol = FirstCol + 2
Zcol = FirstCol + 3
xlSheet.Cells(CurRow, IDCol).Value = "'Point ID"
xlSheet.Cells(CurRow, Xcol).Value = "'X Coord"
xlSheet.Cells(CurRow, Ycol).Value = "'Y Coord"
xlSheet.Cells(CurRow, Zcol).Value = "'Z Coord"
CurRow = CurRow + 1
Set Feature = Part.FirstFeature
While Not Feature Is Nothing
If Feature.GetTypeName2 = "RefPoint" Then
Set myRefPoint = Feature.GetSpecificFeature2
Set myMathPt = myRefPoint.GetRefPoint
ptData = myMathPt.ArrayData
xlSheet.Cells(CurRow, IDCol).Value = Feature.Name
xlSheet.Cells(CurRow, Xcol).Value = Format(ptData(0) * SF, FMAT)
xlSheet.Cells(CurRow, Ycol).Value = Format(ptData(1) * SF, FMAT)
xlSheet.Cells(CurRow, Zcol).Value = Format(ptData(2) * SF, FMAT)
CurRow = CurRow + 1
End If
Set Feature = Feature.GetNextFeature
Wend
End Sub-
Exporting x,y,z corrdinates
Ed Morris Jan 23, 2009 7:27 AM (in response to Josh Brady)Dear Josh,
Thank you. That is exactly what I needed. I realise now how using macros may be powerful tool if one knows how to exploit them!
Is there a good source I could avail of for one to learn macros in Solidworks?
Cheers
Ed -
Re: Exporting x,y,z corrdinates
Steven Bird Oct 14, 2009 1:28 PM (in response to Josh Brady)Josh,
Is it hard to tweak this macro code to look for points in a 3d sketch rather than ref points? If you can do this that would be very helpful for me. I would appreciate it very much. I have tried to get this macro to run, just to see how it works, but have been unsuccessful. How do I use this code? When I run it in SW it does nothing....there is no error. I'm a newbie, so what's the most common newbie mistake?
What would really be ideal for me and my company would be to be able to not only export the points, but to export the points in a user defined order. In my wildest fantasies I we would be able to select a point, hit a button and have it copy the xyz's to a spreadsheet or text file. Wow, that would be awesome. I don't know what it would take to do that? Even if we can't pick the order, an export macro will help tremendously.
Thanks for any help or insight that you can give.
Cody
-
Re: Exporting x,y,z corrdinates
Nick Grisco Oct 14, 2009 3:31 PM (in response to Steven Bird)Cody,
Attached is a macro that I've been using for a while that exports 3Dsketch point to an excel file. Just select the 3Dsketch in your feature tree, run the macro and then format your table anyway you would like. The only thing I have run into with this macro is if any of the points have coincident relationships to other points, you will get double coordinates in your table. Hope that works for you!
-
Create Data Table.swp.zip 12.3 KB
-
Re: Exporting x,y,z corrdinates
Cody Munk Oct 19, 2009 7:17 PM (in response to Nick Grisco)Thanks Nick,
It works great. I have tried to modify the code to give me 8 decimal places. If I change anything VB crashes when I try and run it. Weird. I can't figure it out. Do you have any ideas?
If Not sp Is Nothing And Not sheet Is Nothing And Not exApp Is Nothing Then
sheet.Cells(3 + i, 1).Value = "Pt. " & i + 1
sheet.Cells(3 + i, 2).Value = Round(sp.X * 1000 / 1, 8)
sheet.Cells(3 + i, 3).Value = Round(sp.Y * 1000 / 1, 8)
sheet.Cells(3 + i, 4).Value = Round(sp.Z * 1000 / 1, 8)
exApp.Columns.AutoFitIf Not sp Is Nothing And Not sheet Is Nothing And Not exApp Is Nothing Then
sheet.Cells(3 + i, 1).Value = "Pt. " & i + 1
sheet.Cells(3 + i, 2).Value = sp.X
sheet.Cells(3 + i, 3).Value = Round(sp.Y * 1000 / 1, 3)
sheet.Cells(3 + i, 4).Value = Round(sp.Z * 1000 / 1, 3)
exApp.Columns.AutoFitThanks,
Cody
SW 2009 sp2.1 x64 xp
VB 6.5
-
Re: Exporting x,y,z corrdinates
Nick Grisco Oct 20, 2009 6:32 AM (in response to Cody Munk)I'm not sure what's happening on your end. I tried changing the 3 to 8 like you did and it worked fine for me. I attached my new macro I saved for 8 decimal places. See if that one works any different for you.-
Re: Exporting x,y,z corrdinates
Cody Munk Oct 20, 2009 6:15 PM (in response to Nick Grisco)Thanks Nick,
Although I couldn't get this macro to work on my 64 bit pc, I was able to get it to work on a 32 bit machine. Weird.
Thanks a lot!
Cody
-
-
-
Re: Exporting x,y,z corrdinates
1-FVVJBO Jun 10, 2010 2:08 PM (in response to Nick Grisco)This marco works great but is there a way to only export the center point of arc in a sketch?
Thanks,
Chris
-
-
-
Re: Exporting x,y,z corrdinates
Mark Greenwell Oct 20, 2009 7:20 AM (in response to Josh Brady)Hi Josh
Is there any chance you could just post the macro and not the code.
I have tried to copy and paste the code but could not get it to work. Don't know if i did this right.
Thanks
Mark (Solid|Works 2009)
-
Re: Exporting x,y,z corrdinates
1-IQCD4D Dec 8, 2009 10:47 AM (in response to Josh Brady)Hi Josh, I also tried it but the macro stops at the first 'dim' line with a 'user defined type not defined' error.
My doubt is that "sldworks.sldworks" is not really a 'type'
Do you know of the problem?
Giotto
-
-
Re: Exporting x,y,z corrdinates
Sammy Redshaw Feb 21, 2012 9:41 AM (in response to Sammy Redshaw)done it
Option Explicit
Dim Feature As SldWorks.Feature
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim profileFeature As Sketch
Dim sketchpoints As Variant
Dim sketchPoint As SldWorks.sketchPoint
Dim i As Integer
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Const FirstRow As Long = 4
Const namerow As Long = 3
Dim FirstCol As Long
Dim CurRow As Long
Dim IDCol As Long
Dim Xcol As Long
Dim Ycol As Long
Dim Zcol As Long
Dim v As Long
'To run this macro open the model and run macro
'You have been warned this with travese through allsketchesSub main()
'open and format the excel sheet
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets("Sheet1")CurRow = FirstRow
FirstCol = 2
IDCol = FirstCol
Xcol = FirstCol + 1
Ycol = FirstCol + 2
Zcol = FirstCol + 3
xlSheet.Cells(2, IDCol).Value = "All values are in mm"
xlSheet.Cells(CurRow, IDCol).Value = "'Point ID"
xlSheet.Cells(CurRow, Xcol).Value = "'X Coord"
xlSheet.Cells(CurRow, Ycol).Value = "'Y Coord"
xlSheet.Cells(CurRow, Zcol).Value = "'Z Coord"
CurRow = CurRow + 1
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
Do While Not swFeat Is Nothing
Set swSubFeat = swFeat.GetFirstSubFeature
' Process feature
DoFeature swFeat
Do While Not swSubFeat Is Nothing
' Process feature
DoFeature swSubFeat
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
Set swFeat = swFeat.GetNextFeature
Loop
End SubPrivate Sub DoFeature(feat As Feature)
If feat.GetTypeName2 = "3DProfileFeature" Then
' Do the business on the feature
Set profileFeature = feat.GetSpecificFeature2()
If CurRow > 5 Then
CurRow = FirstRow
FirstCol = FirstCol + 5
IDCol = FirstCol
Xcol = FirstCol + 1
Ycol = FirstCol + 2
Zcol = FirstCol + 3
xlSheet.Cells(2, IDCol).Value = "All values are in mm"
xlSheet.Cells(CurRow, IDCol).Value = "'Point ID"
xlSheet.Cells(CurRow, Xcol).Value = "'X Coord"
xlSheet.Cells(CurRow, Ycol).Value = "'Y Coord"
xlSheet.Cells(CurRow, Zcol).Value = "'Z Coord"
' Get the name
xlSheet.Cells(namerow, IDCol).Value = "Sketch Name: " & feat.Name
CurRow = CurRow + 1
v = 0
Else
' Get the namae
xlSheet.Cells((namerow), IDCol).Value = "Sketch Name: " & feat.Name
End If
' Get the sketch segments
sketchpoints = profileFeature.GetSketchPoints2
' Loop all segments
For i = 0 To UBound(sketchpoints)
Set sketchPoint = sketchpoints(i)
'Export points in mm to Excel
xlSheet.Cells(CurRow, IDCol).Value = ".Pt" & v + 1
xlSheet.Cells(CurRow, Xcol).Value = Format(sketchPoint.X * 1000)
xlSheet.Cells(CurRow, Ycol).Value = Format(sketchPoint.Y * 1000)
xlSheet.Cells(CurRow, Zcol).Value = Format(sketchPoint.Z * 1000)
CurRow = CurRow + 1
v = v + 1
Next
End If
End SubNeeds the code cleaning up a bit and some dialog boxes putting in. only works for 3d sketched not sure how to do it for 2d sketches as well which be xz or zy or xy?
can you help?
-
Re: Exporting x,y,z corrdinates
mehrdad keyno Dec 13, 2012 2:19 PM (in response to Sammy Redshaw)Dear Sammy Redshaw
tnx for your code , but above code just export spline points, which are created from, Is there any way to split the spline with the predefined segment length and then export the points
-
-
-
-
Exporting x,y,z corrdinates
Josh Brady Jan 23, 2009 9:44 AM (in response to Ed Morris)If you are already experienced with VB or VBA then Luke Malpass has a book, and the API help is pretty decent once you figure out how the object structure works. If you can get hold of the API help for 2008 it's much easier to read than 2009's. If you don't have previous programming experience, I would advise getting started writing macros in Excel. There are lots of VBA for Excel tutorials available on the web. -
Re: Exporting x,y,z corrdinates
PRAKASH BABU Mar 18, 2011 12:27 AM (in response to Ed Morris)Hi All,
In SolidWorks We have an option for exporting Points which in turn create curves and points as output. Go to Add-ins and switch ON Scan to 3D option. Then click Curve Wizard Feature and under creation method use discrete and under Mesh/Cloud/File select Browse and under files of type choose Text files (.txt, .csv) and choose appropriate file and apply. You can able to see a curve with points generated. Then create a line thru the points and hide the curve. Hope this amy help you. Find the attached image for your reference.
Regards,
Prakash.
-
scanto3d.JPG 87.4 KB
-
Re: Exporting x,y,z corrdinates
Yasaman Khodadadegan Nov 18, 2011 7:45 PM (in response to PRAKASH BABU)Hi Prakash,
I tried what you mentioned to export points and I exactly followed your instruction in 3D Scan, but it does not save any point in .txt file. If you have tried it, may you give me more details. I created a blank .txt file and browse it when choosing text files since it requires selecting a file as well.
Thanks,
Yasaman
-