Adding Variant array to Selection set

Adding Variant array to Selection set

Anonymous
Not applicable
205 Views
2 Replies
Message 1 of 3

Adding Variant array to Selection set

Anonymous
Not applicable
In my VBA application I have the following code:

ct = objBlk.Count
ReDim ssObjs(0 To ct - 1) As Variant
Set wbSS = ThisDrawing.SelectionSets.Add("SS2")
If Err Then
ThisDrawing.SelectionSets.Item("SS2").Delete
Set wbSS = ThisDrawing.SelectionSets.Add("SS2")
End If
For i = 0 To ct - 1
Set ssObjs(i) = objBlk.Item(i)
Next
wbSS.AddItems ssObjs

The last line does not seem to work, i.e. the ssObjs variant array has the
entities copied from the block, but it does not get added to the wbSS
selection set. I watched the varaible wbSS and it remains empty after the
code has run. What am I doing wrong?

Dilip Bhandarkar
0 Likes
206 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Declare another variable as AcadEntity(), fill it with your selected
objects, then assign that variable to a Variant:

Dim WbSS() as AcadEntity, ssObjs as Variant, FinalSS as AcadSelectionSet

Set FinalSS = ThisDrawing.SelectionSets.Add("ss")

For i = 0 to objBlk.Count -1
ReDim Preserve WbSS(0 to i)
Set WbSS(i) = objBlk.Item(i)
Next

ssObjs = WbSS
FinalSS.AddItems ssObjs
0 Likes
Message 3 of 3

Anonymous
Not applicable
Dilip Bhandarkar wrote in message <[email protected]>...
>In my VBA application I have the following code:
>
> For i = 0 To ct - 1
> Set ssObjs(i) = objBlk.Item(i)
> Next
> wbSS.AddItems ssObjs
>

Dilip,

If objBlk is not an active layout or the modelspace block
then I would not expect this code to work. If objBlk is just
some random block definition you will be successful in
copying the object references to the array, but since these
entities don't exist in a user selectable space they won't
be appended to the selection set.

Remember that selection sets created programmatically
are just like selections created by a user interactively - with
all the same limitations. Objects must typically be on screen,
etc..

Why don't you describe what it is you're trying to do - because
it seems you're going about it the wrong way.

Cheers-

rdh.
0 Likes