Hi @Anonymous ,
here below a sample code, that could be fixed more but it's a starting point, that should help you with your issue
Public Sub lista_poly()
Dim Myapp As Object
Dim MyDwg As AcadDocument
Dim Obj As AcadObject
Dim Ent As AcadEntity
Dim text As AcadText
Dim w As Worksheet
Dim Ppos() As Double
Dim line As AcadLine
Dim pontos As Double
Dim MySset As AcadSelectionSet
Dim FilterType(4) As Integer
Dim FilterData(4) As Variant
Dim P1(0 To 2) As Double
Dim P2(0 To 2) As Double
R = 2
Set Myapp = GetObject(, "Autocad.application")
Set MyDwg = Myapp.ActiveDocument
Sheets(1).Range("B1") = "X"
Sheets(1).Range("C1") = "Y"
For Each Obj In MyDwg.ModelSpace
If TypeOf Obj Is AcadLWPolyline Then
Line_Pos = Obj.Coordinates
For i = 0 To UBound(Line_Pos) Step 2
Sheets(1).Range("B" & R) = Line_Pos(i)
Sheets(1).Range("C" & R) = Line_Pos(i + 1)
R = R + 1
Next
' GetMaxNumber (Line_Pos)
P1(0) = Line_Pos(0)
P1(1) = Line_Pos(1)
P1(2) = 0
P2(0) = UBound(Line_Pos) - 1
P2(1) = UBound(Line_Pos)
P2(2) = 0
On Error Resume Next
Set MySset = MyDwg.SelectionSets.Add("MySel")
If Err.Number <> 0 Then
MyDwg.SelectionSets.Item("MySel").Delete
Set MySset = MyDwg.SelectionSets.Add("MySel")
End If
FilterType(0) = -4
FilterData(0) = "<or"
FilterType(1) = 0
FilterData(1) = "TEXT"
FilterType(2) = 0
FilterData(2) = "MTEXT"
FilterType(3) = 0
FilterData(3) = "DIMENSION"
FilterType(4) = -4
FilterData(4) = "or>"
'MySset.Select acSelectionSetWindow, P2, P1, FilterType, FilterData
MySset.Select acSelectionSetAll, , , FilterType, FilterData
If MySset.Count >= 1 Then
For a = 0 To MySset.Count
Select Case MySset.Item(a).ObjectName
Case "AcDbText"
Sheets(1).Range("A" & R) = MySset.Item(a).TextString
Case "AcDbRotatedDimension"
Debug.Print "DIMENSION ROTATED"
Sheets(1).Range("D" & R) = MySset.Item(a).Measurement
R = R + 1
End Select
Next
End If
End If
Next
End Sub
It's based upon a polyline, see attached drawing.
The part of code 'MySset.Select acSelectionSetWindow, P2, P1, FilterType, FilterData, could be used for refine text search related inside the founded polyline.
I mean, that whenever you find a polyline object, and you are retrieving the coordinates, you can with a function find the max and min value inside the vertex coordinates array, based upon that value in the coordinates array are stored by X, following Y value for each vertex.
So if you search TEXT, and DIMENSION with Selection Set around the MIN and MAX vertex coordinates value, you will be sure to catch the text and dimensions of found polyline on drawing no more.
In the next days I'll try to develop this part too and make some test, I'll keep you informed.
I hope above could help you more.
See attached sample xlsm (with macro inside) and drawing with polyline.