22 | 02 | 2017

Export Polyline Coordinates to Textfile

This code exports all polyline coordinates to a textfile located at C:\TEST.txt.

Public Sub WriteAllPolylinesToFile(strFilename As String)
Dim objSelectionSet As AcadSelectionSet
Dim intGroupCode(0) As Integer
Dim varDataCode(0) As Variant
Dim objAcadPoly As AcadLWPolyline
Dim lngL As Long

On Error Resume Next

'do Lightweight polylines
intGroupCode(0) = 0
varDataCode(0) = "LWPolyline"


If Err Then Err.Clear

'create a selection of all lightweight polylines
Set objSelectionSet = ThisDrawing.SelectionSets.Add("Poly")
objSelectionSet.Select acSelectionSetAll, , , intGroupCode, varDataCode

'write the polyline vertices to file
Open strFilename For Append Access Write As #10
Write #10, "Polyline vertices"
'go through each polyline object
For Each objAcadPoly In objSelectionSet
For lngL = 0 To UBound(objAcadPoly.Coordinates)
Write #10, objAcadPoly.Coordinates(lngL)
Next lngL
Next objAcadPoly
Close #10

If Err Then
Kill strFilename
MsgBox "There were errors, no file created!"
End If
End Sub

Sub TestExportFunction()

WriteAllPolylinesToFile "C:\TEST.txt"
End Sub

Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles