get points coordinates of a line

Hello everybody,

I would like to draw a line and get all points coordinates of this line, is it possible?

Thanks

SolidworksApi macros
Answers 1
SF
SF 2014-04-22 Best Answer

This gets the coordinates of the first line on a sketch called "3DSketch1". Hope it helps

Option Explicit

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swSketchLine As SldWorks.SketchLine

Dim swSelMgr As SldWorks.SelectionMgr

Dim Point1 As SldWorks.SketchPoint

Dim Point2 As SldWorks.SketchPoint

Dim X1, Y1, Z1, X2, Y2, Z2 As Double

Sub main()

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

   

    Call swModel.Extension.SelectByID2("Line1@3DSketch1", "EXTSKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)

   

    Set swSelMgr = swModel.SelectionManager

    Set swSketchLine = swSelMgr.GetSelectedObject6(1, -1)

    Set Point1 = swSketchLine.GetStartPoint2

    Set Point2 = swSketchLine.GetEndPoint2

   

    X1 = Point1.X

    Y1 = Point1.Y

    Z1 = Point1.Z

   

    X2 = Point2.X

    Y2 = Point2.Y

    Z2 = Point2.Z

End Sub