Message 1 of 2

Not applicable
02-12-2017
04:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Private Sub pline_coordinates() Dim oSset As AcadSelectionSet Dim oEnt As AcadEntity Dim fcode(0) As Integer Dim fData(0) As Variant Dim dxfcode, dxfdata Dim setName As String Dim i As Integer Dim n As Integer Dim s As String fcode(0) = 8 '0 8 fData(0) = "_SP_Direk" '"LWPOLYLINE" "_SP_Direk" dxfcode = fcode dxfdata = fData setName = "$Plines$" '// make sure the selection set does not exist For i = 0 To ThisDrawing.SelectionSets.Count - 1 If ThisDrawing.SelectionSets.Item(i).Name = setName Then '// if this named selection set is already exist then delete it ThisDrawing.SelectionSets.Item(i).Delete Exit For End If Next i '// add new selection set with this name Set oSset = ThisDrawing.SelectionSets.Add(setName) oSset.Select acSelectionSetAll, , , dxfcode, dxfdata On Error GoTo Err_Control '// loop through the all light polylines ReDim plineAr(0 To oSset.Count - 1, 0 To 4) As Variant For n = 0 To oSset.Count - 1 Dim cEnt As AcadEntity Set cEnt = oSset.Item(n) Dim oPline As AcadLWPolyline Set oPline = cEnt Dim coord As Variant '// get coordinates coord = oPline.Coordinates '// collect polyline handles and points into a two-dimensional array plineAr(n, 0) = oPline.Handle plineAr(n, 1) = coord(0) ' <--X start point plineAr(n, 2) = coord(1) ' <--Y start point plineAr(n, 3) = coord(UBound(coord) - 1) ' <--X end point plineAr(n, 4) = coord(UBound(coord)) ' <--Y end point Next n '// clean up memory oSset.Delete '// do what you want with array 'plineAr' here, e.g. write data to the text file etc. Open "C:\AllPlines.txt" For Output As #1 'Open file for output For n = 0 To UBound(plineAr, 1) s = "" For i = 0 To UBound(plineAr, 2) s = s & CStr(plineAr(n, i)) & "," Next i Write #1, Left(s, Len(s) - 1) 'Write comma-delimited data (cut the last comma from string) Next n Close #1 'Close file Err_Control: MsgBox Err.Description End Sub
Hi there,
i found a code that exports all polyline coordinates to txt file.
but when i'm trying to select a layer and export just that layer, i get an error "Type Mismatch".
it works when
fcode(0) = 0 fData(0) = "LWPOLYLINE"
Solved! Go to Solution.