AutoCAD macro to Extract Coordinates of a 3D Polyline

Extract Coordinates of 2D Polyline

Join online Course on AutoCAD VBA Programming

Following is the VBA code to extract Coordinates of a 3D Polyline in AutoCAD drawings.

Sub ThreeDPolylineCords()
Dim XLnCADObject As Acad3DPolyline
Dim i As Integer
Dim x As Double, y As Double, z As Double
Open “E:3DPolylineCordinates.txt” For Output As #1
Dim basePnt As Variant
ThisDrawing.Utility.GetEntity XLnCADObject, basePnt, “Select a 3D Polyline”
Dim Cords As Variant
Cords = XLnCADObject.Coordinates
For i = LBound(Cords) To UBound(Cords) Step 3
x = Format(XLnCADObject.Coordinates(i), “0.000”)
y = Format(XLnCADObject.Coordinates(i + 1), “0.000”)
z = Format(XLnCADObject.Coordinates(i + 2), “0.000”)
Print #1, x; y; z
Next i
Dim length As Double
length = Format(XLnCADObject.length, “0.000”)
Print #1, vbCrLf; “Length of the selected LW Polyline is “; length
Print #1, vbCrLf; “Number of vertices of the selected polyline is “; (UBound(Cords) + 1) / 2
Close (1)
End Sub

Join online Course on Scripting in AutoCAD

Macros (VBA for AutoCAD)

Scripting in AutoCAD

Tips & Tricks in AutoCAD