Storing SelectionSets

Storing SelectionSets

Anonymous
Not applicable
1,021 Views
3 Replies
Message 1 of 4

Storing SelectionSets

Anonymous
Not applicable

Hi, I had this question posted under Kean Walmsley's blog, but the answer confused me, so I would like to discuss it a little more.

 

 

hi Kean,
I'm trying to find some effective way to store SelctionSets, I was thinking about groups, but I need the possibility of overlapping entities
the group is created using ObjectIDs, but how does it retain when session ends? Does it convert the oIDs to Handles somehow, when the drawing is closed?

 

Hi Matus,

You can store ObjectIds for objects inside a drawing (such as inside an XRecord in a dictionary): these are ultimately memory pointers (and so transient in nature), but AutoCAD remaps them when it loads a drawing. So they will be consistent within the context of a drawing.

If you need to cross drawing boundaries, then you'll need handles.

 

 

What I did, is that I get the handles of objects in selection set, store them in an XRecord in DBDictionary, and then, when I'm loading them, I get ObjectIDs from those Handles and build SelectionSets using the SelectionSet.FromObjectIds

this works, so I'm fine, but I would like to understand the answer from Kean

 

I thought, that ObjectIDs are generated every time AutoCAD opens the drawing, while Handles stay the same, then how can I access the same entity from stored ObjectID, when I close/reopen the drawing? While handles should be the same for each entity in every opened drawing, so if I open one drawing twice, than the only way to address the entity in the correct drawing would be to use the ObjectID. Kean seams to be explaining it the opposite way.

So did I misunderstand this answer from him, or did I misunderstand the whole concept of Handles and ObjectIDs?

 

Sorry to talk about you in third person Kean, I would really appreciate if you could answer this personally.

 

Matus

0 Likes
Accepted solutions (1)
1,022 Views
3 Replies
Replies (3)
Message 2 of 4

JamesAllen
Participant
Participant
Accepted solution

Hi Matus,

 

What Kean was explaining is that the numeric values of ObjectIds change for each session, but AutoCAD automatically updates properly stored references to ObjectIds so that they still point to the same object.  Handles on the other hand, as you said, do not change.

 

So you properly store (e.g. in the XRecord he mentioned) an ObjectId 222 in the drawing, close and reopen, if that ObjectId becomes 333 then the XRecord 222 you stored will also have become 333, thus still pointing to the same object.  However if you stored 222 in another drawing or as a piece of text (anywhere AutoCAD doesn't know to look for it), then it is still 222 which is no longer valid, or maybe worse now points to something else.  But since the handle won't change, you can store it however you want wherever you want and it will always refer to the same object (provided it's still there, etc.).

 

Hopefully that helps a little and doesn't just add to the confusion...

 

James

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thank you, James, this really explained the thing.

I was storing ObjectIDs as text before and it didn't work right (now I know why), so I moved to Handles

0 Likes
Message 4 of 4

JamesAllen
Participant
Participant

You're welcome.  Thank you for following up.

0 Likes