Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selection Set Manipulation (VBA) 1

Status
Not open for further replies.

mochamoo

Technical User
Mar 8, 2005
8
US
When you get a selection set from the user, how are the items stored. Are they stored as Objects or as whatever they are ??? Is a selection set an array of objects?? I cant find much on this topic.

Here is some code. It is a simple little macro that is supposed to isolate a single layer and turn all other off. If anyone can help, please do.

Some of this is pseudocode:

1 Sub Isolate()
2 Dim myLayer As AcadLayer
3 Dim Selection As AcadSelectionSet
4
5 Create SelectionSet
6 Let user select an item in the current drawing
7
8 'Here is where I need help. I am not sure how to figure out what layer
9 'the object is on.
10 Set myLayer = Selection(0).Layer
11
12 MsgBox "Item is on layer" & Selection(0).Layer
13
14 For Each Layer is ThisDrawing
15 If Layer = myLayer Then Layer should be on
16 Else Layer should be off.
17 Next
18
19 End Sub

The funny thing is that line #10 gives me an error, but line 12 doesn't. Line 12 will print correctly and tell me what layer the user selected object is on. Why won't line 10 work. Also, line 14 doesn't work. I don't think I can use "ThisDrawing". My main concern is that I don't understand the internal storage of a selection set. How is each item stored and how is each item accessed. Are they indexed. Do I need to take them out of the selction set before manipulating them.

I have looked extensively for information on this subject but I can find none. Please help. If you know any good tutorials or books on this subject please let me know. Thanks
 
Hi mochamoo,

Selection set entities are stored as just that, pointers to the enities themselves. You don't need to "extract" them from the selection set as the selection set is just a collection of pointers. To make things easier, you may loop through them as in:

Code:
Dim Ent as AcadEntity

For Each Ent in Selection
  ...
Next Ent

The reason line 10 is producing an error, is returning a layer property produces a string - not a layer object - for line 10 to work, you would change it to this:

Code:
Set myLayer = Thisdrawing.Layers(Selection(0).Layer)

Finally line 14 should read:

Code:
For Each Layer [red]in[/red] ThisDrawing[red].Layers[/red]


HTH
Todd
 
Thanks a lot, it works perfectly. I really appreciate the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top