Reference to entities(id)
-
I want to get references to entities for passing strings to webdialog.
What do one use safely without riscing getting them gb'd ?
Was gonna use entityID but this got me a tad worried:
http://sketchucation.com/forums/viewtopic.php?f=180&t=49354&p=443630&hilit=entity+id#p443630Although here Dan mention object_id or id
http://sketchucation.com/forums/viewtopic.php?f=180&t=47845&p=429085&hilit=entity+id#p429085I guess one could assign an attribute with a timestamp, but it feels like overkill..
Further detail. Id does not need to be kept between sessions. And perhaps I'm going to simulate the entities geometry with the drawclass & openGL, = the entities remain unaltered.
Last part not sure yet.. -
A unique 'tid' [timestamp-id] attached to the object as an attribute should persist across sessions.
If an object is deleted but then undone the replacement object should be given the 'tid' [as is its layer/material etc], BUT its 'elementID' will then differ.
The normal elementID, object_id/id etc should persist during a session, but they can be 'lost' during some operations, like undo and operations that create new but otherwise similar looking geometry - like PushPull... where replacement geometry does not keep the original's 'id'...It depends what you are doing with any 'id' for and the likelihood of it getting lost in transit...
-
Thank you TIG
That sounds reasonable.
Sounds like [timestamp-id] attribute might be the way to go then.Regarding simulating geometry via view.draw OPENGL. I was wrong about avoiding this issue.
Still run into the same problem with ID's gb'd when altering the same entities
at a later stage, (as you pointed out). -
What are you doing with these entity ids?
-
@unknownuser said:
I want to get references to entities for passing strings to webdialog.
I think you have to interpret my question literally Thomthom. Cause I'm not really sure what I need yet. Not in a state yet for testing this proposed solution anyhow.
A string going back and forth JS <-> Ruby should contain enough uniq information so I can get a hold of the correct entity in Sketchup.
Now there are some considerations of tolerance to this and altering of geometry,
(as TIG pointed out).At this stage maybe one should try the easiest approach, with attributes.
Assigning attributes is pretty painless. However theres one extra step to remove the attribute when swithcing or deleting selection.I guess it's also possible to store selections in Ruby array or Hash and reference to that by index or key (coming from JS), and have a more general text-represenation in Webdialog?
Id's are named quite cryptic anyway with <> illegal html characters..
edit: Doing it this way one still would face the same issue, regarding lost id's from edited geometry.I'm open for suggestions, not in a hurry solving this problem..
-
You can always test an object to see if it is still valid ...
obj.valid?
But if you are storing ids ...
new_object_ref = ObjectSpace._id2ref(some_id_integer) # test if it's valid; if new_object_ref.is_a?(Sketchup;;Entity) && new_object_ref.valid? # do something with new_object_ref end
-
Yep, solid tip.
Thank you Dan.
Advertisement