How to store an Entity between sessions?
-
I would like to be able to store an entity or a reference to an entity between sessions, and retrieve the entity quickly (i.e. without iterating every entity in the model). Is there a way? Entity.entityID doesn't last between sessions, and placing entities in attribute dictionaries isn't working for me.
-
Using Attributes is about the only way - what isn't working about them?
-
@jim said:
Using Attributes is about the only way - what isn't working about them?
m = Sketchup.active_model #<Sketchup;;Model;0xdc02f80> m.set_attribute("mydict", "mykey", m.selection[0]) #<Sketchup;;Face;0xe286438> m.get_attribute("mydict", "mykey") nil -
You have to give the entity an enduring attribute like a 'guid' based on say
Time.now.to_f+rand...
As it's a group you can iterate all definitions using .group? and break once you have a match... -
Hmm I suppose since I will be grouping the Entity, I could iterate all the groups in the model to find it... less intense than iterating entities, but still not ideal...
This seems like it must be a common problem. Plugins will inevitably have special geometry that they want to tag and keep track of. Some of the messier models I've worked with have been >100MB and iterating model.entities isn't acceptable.
-
@tig said:
You have to give the entity an enduring attribute like a 'guid' based on say
Time.now.to_f+rand...
As it's a group you can iterate all definitions using .group? and break once you have a match...Yea, I've done this in the past... number of groups should be WAY less than number of entities. Sure there's no other way?
-
@draftomatic said:
@tig said:
You have to give the entity an enduring attribute like a 'guid' based on say
Time.now.to_f+rand...
As it's a group you can iterate all definitions using .group? and break once you have a match...Yea, I've done this in the past... number of groups should be WAY less than number of entities. Sure there's no other way?
That's the way I do it, when I have to...
If you have to save a particular 'thing' across sessions it must have some sort of enduring 'handle' - so if you think about it... no matter what that is you'll have to sort through lists of 'similar things' to find it... be it 'naming', 'layer', 'guid-attribute', 'material' or whatever... you'll need to 'sift' the model's entities when you reopen it... -
Thanks TIG

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement