-
Macro to capture points in 3d sketch and export to excel
Charles Culp Aug 16, 2007 5:07 PM (in response to Jeremy Owen)You will actually want to create the macro in Excel, then have it"pull" the points from Solidworks. You can look inthe API help for Solidworks for how to grab points. You willprobably want to have the 3D Sketch open in Solidworks, then"find points" and "get next point" and loopthrough all the points. I'm not sure what the commands areoff-hand, and I can't seem to get Solidworks API help to comeup!
Hopefully someone else can give you more direction, mine was rathergeneral. -
Macro to capture points in 3d sketch and export to excel
SolidAir Aug 16, 2007 11:51 PM (in response to Jeremy Owen)Jowen,
The following code was taken from API help: Get Sketch Points Example (VB). I had to clean it up some because it was missing the Sub main () statement and would not have run. I also brought it up to more current standards of using the Option Explicit statement and using early binding when declaring SolidWorks object variables. This code just shows you how to get the points from SolidWorks, you will have to get them to Excel.
SA
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim theSketch As SldWorks.Sketch
Dim sketchPointArray As Variant
Dim pointCount As Long
Dim i As Long
Dim xValue As Double
Dim yValue As Double
Dim zValue As Double
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set theSketch = Part.GetActiveSketch2
sketchPointArray = theSketch.GetSketchPoints2
pointCount = UBound(sketchPointArray)
For i = 0 To pointCount
' Get the coordinates
xValue = sketchPointArray(i).X
yValue = sketchPointArray(i).Y
zValue = sketchPointArray(i).Z
Debug.Print i, xValue, yValue, zValue
Next i
End Sub -
Macro to capture points in 3d sketch and export to excel
Eyal Siryon Aug 17, 2007 9:22 AM (in response to Jeremy Owen)attached is a macro that saves the selected sketch entire points to a comma seperate text file.
hope that does the trick. the macro was posted by me in the israeli var web site.
www.solidworks.co.il-
ExportXYZ2TXT.zip 12.4 KB
-
Macro to capture points in 3d sketch and export to excel
Nick Vande Waerdt Aug 21, 2007 5:06 PM (in response to Eyal Siryon)ESIRYON,
Thank you, that works wonderfully. One question though, isthere a way to change the coordinate system? It automaticallyuses the Assembly Origin, and I would like to use a user-definedcoordinate system. Any ideas for me? Thanks.
Nick Vande Waerdt-
Macro to capture points in 3d sketch and export to excel
Eyal Siryon Aug 26, 2007 11:50 AM (in response to Nick Vande Waerdt)Hi,
you can always ask the user to select a coordinate system or a component along with the sketch.
before analyising the sketch you should look for the selected object (coordinate or component) and get thetransform of this feature.
look under the api help for the subject "transform" or "Coordinate system" or "Component2::Transform2"
-
Re: Macro to capture points in 3d sketch and export to excel
Sammy Redshaw Feb 17, 2012 9:44 AM (in response to Eyal Siryon)I have been given a macro to generate a complex surface which has worked. I don't know how to open the SWP file and pull the ordinate points out.
So How do you loop exportxyz2txt it through a hundred plus sketches and pull the sketch names and geometry?
-
-
-
-
Re: Macro to capture points in 3d sketch and export to excel
Alex Morrison Nov 21, 2013 11:41 PM (in response to Jeremy Owen)Hi All,
The macro at this link may be useful: http://solidtecsolutions.blogspot.com.au/2012/06/this-blog-shows-you-how-to-create.html
I'm still playing with it. it exports the coordinates in meters.
-
Re: Macro to capture points in 3d sketch and export to excel
Deepak Gupta Nov 22, 2013 1:03 AM (in response to Alex Morrison)it exports the coordinates in meters.
Multiple the value with 1000 to have coordinates values in MM.
-
-
Re: Macro to capture points in 3d sketch and export to excel
Alexander Salimian May 19, 2015 10:54 AM (in response to Jeremy Owen)If you wish to output the coordinates of reference points, this method will output the to the immediates window the X Y Z of the first 300 points. Haven't gotten around to making it work for a selection set of all reference points, so it just picks by name.
Dim swApp As Object, Part As Object Dim selectStatus As Boolean, boolstatus As Boolean Dim swModelDocExt As SldWorks.ModelDocExtension Dim swMeasure As SldWorks.Measure Sub main() Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Set swModelDocExt = Part.Extension Debug.Print (String(50, "=")) Debug.Print ("Pt" & vbTab & "X-Coor (m)" & vbTab & "Y-Coor (m)" & vbTab & "Z-Coor (m)") For i = 0 To 300 selectStatus = Part.Extension.SelectByID2("Point" & i, "DATUMPOINT", 0, 0, 0, False, 0, Nothing, 0) Set swMeasure = Part.Extension.CreateMeasure boolstatus = swMeasure.Calculate(Nothing) If (selectStatus) Then: Debug.Print (i & vbTab & swMeasure.X & vbTab & swMeasure.Y & vbTab & swMeasure.Z) Next Part.ClearSelection2 True End SubEdit: Left out the calculate step on line 17 by mistake.