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.
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.
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
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
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.
ExportXYZ2TXT.zip 12.4 KB
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
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"
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?
it exports the coordinates in meters.
Multiple the value with 1000 to have coordinates values in MM.
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 Sub
Edit: Left out the calculate step on line 17 by mistake.