- Sub selEntByPline()
- On Error Resume Next
- Dim objCadEnt As AcadEntity
- Dim vrRetPnt As Variant
- Dim gpCode(0) As Integer
- Dim dataValue(0) As Variant
- Dim ntexts As Integer, iText As Integer
- Dim myText As AcadText
- ThisDrawing.Utility.GetEntity objCadEnt, vrRetPnt
- If objCadEnt.ObjectName = "AcDbPolyline" Then
- Dim objLWPline As AcadLWPolyline
- Dim objSSet As AcadSelectionSet
- Dim dblCurCords() As Double
- Dim dblNewCords() As Double
- Dim iMaxCurArr, iMaxNewArr As Integer
- Dim iCurArrIdx, iNewArrIdx, iCnt As Integer
- Set objLWPline = objCadEnt
- dblCurCords = objLWPline.Coordinates
- iMaxCurArr = UBound(dblCurCords)
- If iMaxCurArr = 3 Then
- ThisDrawing.Utility.Prompt "The selected polyline should have minimum 2 segments..."
- Exit Sub
- Else
- iMaxNewArr = ((iMaxCurArr + 1) * 1.5) - 1
- ReDim dblNewCords(iMaxNewArr) As Double
- iCurArrIdx = 0: iCnt = 1
- For iNewArrIdx = 0 To iMaxNewArr
- If iCnt = 3 Then
- dblNewCords(iNewArrIdx) = 0
- iCnt = 1
- Else
- dblNewCords(iNewArrIdx) = dblCurCords(iCurArrIdx)
- iCurArrIdx = iCurArrIdx + 1
- iCnt = iCnt + 1
- End If
- Next
- Set objSSet = ThisDrawing.SelectionSets.Add("SELENT")
- gpCode(0) = 0: dataValue(0) = "TEXT"
- objSSet.SelectByPolygon acSelectionSetWindowPolygon, dblNewCords, gpCode, dataValue
- ntexts = objSSet.Count
- For iText = 0 To ntexts - 1
- ' do your stuff here
- ' for instance I'm listing all textstrings of the found objects
- Set myText = objSSet.Item(iText)
- MsgBox ("Found :" & myText.TextString & " - " & objLWPline.Area & "m2")
- Next iText
- objSSet.Delete
- End If
- Else
- ThisDrawing.Utility.Prompt "The selected object is not a 2D Polyline...."
- End If
- If Err.Number <> 0 Then
- MsgBox Err.Description
- Err.Clear
- End If
- End Sub
|