VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VBA code error, about collection

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
classof
633 Views, 3 Replies

VBA code error, about collection

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

3 REPLIES 3
Message 2 of 4
Hallex
in reply to: classof

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'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 4
classof
in reply to: classof

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 ...Smiley Very Happy

Message 4 of 4
Hallex
in reply to: classof

Glad to help Smiley Happy

Cheers

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost