9 Replies Latest reply on May 19, 2015 10:54 AM by Alexander Salimian

    Macro to capture points in 3d sketch and export to excel

    Jeremy Owen
      is it possible to capture points in a 3d sketch and export theX,Y,Z coordinates to excel?
        • Macro to capture points in 3d sketch and export to excel
          Charles Culp
          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
            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
              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
              • Re: Macro to capture points in 3d sketch and export to excel
                Alex Morrison

                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
                  Alexander Salimian

                  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.