hello..
I am using "autocad2006".
I want to know the number of lines and length of lines drawn at current layer.
But it didn't work properly. I don't know why.
Please help me about below code.
Sub LineSelect()
Dim mode As Integer
Dim retval As New Collection
Dim gpCode(0) As Integer
Dim dataValue(0) As Variant
Dim ssetObj As AcadSelectionSet
Dim tempent As AcadEntity
With ThisDrawing
gpCode(0) = 0: dataValue(0) = "LINE"
mode = acSelectionSetAll
On Error Resume Next
If .SelectionSets("SELECT") Then .SelectionSets("SELECT").Delete
On Error GoTo 0
Set ssetObj = .SelectionSets.Add("SELECT")
ssetObj.Select mode, , , gpCode, dataValue
Dim idBlock As Long
idBlock = ThisDrawing.ActiveLayout.Block.ObjectID
Dim i As Integer
For i = 0 To ssetObj.Count - 1
If ssetObj(i).OwnerID = idBlock Then
retval.Add tempent
End If
Next i
MsgBox retval.Count 'number of lines at current layout
Dim Eac As AcadLine
For Each Eac In retval
MsgBox Eac.Length 'ERROR
Next Eac
End With
End Sub
'thank you
Solved! Go to Solution.
Solved by Hallex. Go to Solution.
You've missed one line of code
Option Explicit Sub LineSelect() Dim mode As Integer Dim retval As New Collection Dim gpCode(0) As Integer Dim dataValue(0) As Variant Dim ssetObj As AcadSelectionSet Dim tempent As AcadEntity With ThisDrawing gpCode(0) = 0: dataValue(0) = "LINE" mode = acSelectionSetAll On Error Resume Next If .SelectionSets("SELECT") Then .SelectionSets("SELECT").Delete On Error GoTo 0 Set ssetObj = .SelectionSets.Add("SELECT") ssetObj.Select mode, , , gpCode, dataValue Dim idBlock As Long idBlock = ThisDrawing.ActiveLayout.Block.ObjectID Dim i As Integer ' For i = 0 To ssetObj.Count - 1 ' If ssetObj(i).OwnerID = idBlock Then ' Set tempent = ssetObj(i) '' <--missing line ' retval.Add tempent ' End If ' Next i ''or use this code vlock instead For Each tempent In ssetObj If tempent.OwnerID = idBlock Then retval.Add tempent End If Next tempent MsgBox retval.Count 'number of lines at current layout Dim Eac As AcadLine For Each Eac In retval MsgBox Eac.Length Next Eac End With ThisDrawing.SelectionSets.item("SELECT").Delete End Sub
~'J'~
hallex..
Thank for your help.
These days, I have concerned about the code.
And the troublesome code was easily solved thanks to you.
Thank you, Thank you ...