Accessing items of a newly created collection!

Accessing items of a newly created collection!

Anonymous
Not applicable
103 Views
2 Replies
Message 1 of 3

Accessing items of a newly created collection!

Anonymous
Not applicable
I created a new collection with the following code:

Private Function GetXrefs() As Collection

Dim BlockList As New Collection
Dim iCount As Long
Dim acadObject As AcadBlock
Dim AcadEnt As AcadEntity

'get list of available blocks
For Each acadObject In ThisDrawing.Blocks
If acadObject.IsXRef = True Then
BlockList.Add acadObject.Name, acadObject.Name
End If
Next
'return list of blocks in this drawing
If BlockList.Count > 0 Then
Set GetXrefs = BlockList
Else
Set GetXrefs = Nothing
End If

Now i want to cycle through that list (collection) and do things to the
xrefs contained within the collection so i try this:

Dim BlockList As Collection
Dim objBlock As AcadBlock

' Get list of blocks
Set BlockList = GetXrefs()

For Each objBlock In BlockList
strXrefname = objBlock.Name
Set objBlock = ThisDrawing.Blocks(strXrefname)
UserForm1.ListBox1.AddItem strXrefname

But something is going wrong at the start of the for each statement where i
get the error message " object required".
so i try setting the objblock variable to the blocklist collection item and
i get "Argument not optional"
set objblock = blocklist.item

Can someone please help.
0 Likes
104 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Add the object not the name...

Dim colBlocks As New Collection
Dim oBlk As AcadBlock

For Each oBlk In ThisDrawing.Blocks
If oBlk.IsXref Then
colBlocks.Add oBlk
End If
Next

For Each oBlk In colBlocks
Debug.Print oBlk.Name
Next

Regards,
Jacob Dinardi

Patrick Porter wrote in message
news:48CEF5DE2E0317EAE750AE9650C13F3F@in.WebX.maYIadrTaRb...
I created a new collection with the following code:

Private Function GetXrefs() As Collection

Dim BlockList As New Collection
Dim iCount As Long
Dim acadObject As AcadBlock
Dim AcadEnt As AcadEntity

'get list of available blocks
For Each acadObject In ThisDrawing.Blocks
If acadObject.IsXRef = True Then
BlockList.Add acadObject.Name, acadObject.Name
End If
Next
'return list of blocks in this drawing
If BlockList.Count > 0 Then
Set GetXrefs = BlockList
Else
Set GetXrefs = Nothing
End If

Now i want to cycle through that list (collection) and do things to the
xrefs contained within the collection so i try this:

Dim BlockList As Collection
Dim objBlock As AcadBlock

' Get list of blocks
Set BlockList = GetXrefs()

For Each objBlock In BlockList
strXrefname = objBlock.Name
Set objBlock = ThisDrawing.Blocks(strXrefname)
UserForm1.ListBox1.AddItem strXrefname

But something is going wrong at the start of the for each statement where i
get the error message " object required".
so i try setting the objblock variable to the blocklist collection item and
i get "Argument not optional"
set objblock = blocklist.item

Can someone please help.
0 Likes
Message 3 of 3

Anonymous
Not applicable
THank you So verry much!!!!!!!!!!!!!!

"Jacob Dinardi" wrote in message
news:EC935C8E29FFD349F50E150616F15FFE@in.WebX.maYIadrTaRb...
> Add the object not the name...
>
> Dim colBlocks As New Collection
> Dim oBlk As AcadBlock
>
> For Each oBlk In ThisDrawing.Blocks
> If oBlk.IsXref Then
> colBlocks.Add oBlk
> End If
> Next
>
> For Each oBlk In colBlocks
> Debug.Print oBlk.Name
> Next
>
> Regards,
> Jacob Dinardi
>
> Patrick Porter wrote in message
> news:48CEF5DE2E0317EAE750AE9650C13F3F@in.WebX.maYIadrTaRb...
> I created a new collection with the following code:
>
> Private Function GetXrefs() As Collection
>
> Dim BlockList As New Collection
> Dim iCount As Long
> Dim acadObject As AcadBlock
> Dim AcadEnt As AcadEntity
>
> 'get list of available blocks
> For Each acadObject In ThisDrawing.Blocks
> If acadObject.IsXRef = True Then
> BlockList.Add acadObject.Name, acadObject.Name
> End If
> Next
> 'return list of blocks in this drawing
> If BlockList.Count > 0 Then
> Set GetXrefs = BlockList
> Else
> Set GetXrefs = Nothing
> End If
>
> Now i want to cycle through that list (collection) and do things to the
> xrefs contained within the collection so i try this:
>
> Dim BlockList As Collection
> Dim objBlock As AcadBlock
>
> ' Get list of blocks
> Set BlockList = GetXrefs()
>
> For Each objBlock In BlockList
> strXrefname = objBlock.Name
> Set objBlock = ThisDrawing.Blocks(strXrefname)
> UserForm1.ListBox1.AddItem strXrefname
>
> But something is going wrong at the start of the for each statement where
i
> get the error message " object required".
> so i try setting the objblock variable to the blocklist collection item
and
> i get "Argument not optional"
> set objblock = blocklist.item
>
> Can someone please help.
>
0 Likes