After, I iterated Sketchup.active_model.definitions to read its attributes to find out the origuid to get what definition I wanted. But when the number of definitions increased, it was time-consuming to find out the right definition.
Is there a quick way to get a definition. I am wondering if the index of a definition is a possible solution. Save the index when adding a definition, then access it by the index after. How can I get the index of a definition when it is added. If it will change when adding instances to it?
Thanks a lot. Yes, adding definition A, and its index is 1. If adding more definitions and manipulating the defintion A, does its index 1 change or not?
If it works then you do not need the attributes at all …BUT if someone else (e.g the user manually or other extension) will delete one of the definition then your definition_index will be useless.
If you want to stay with the GUID (which changes each time the definition is edited,) then you can use the Model#find_entity_by_id method (it searches for matching entityID or GUID.)
ADD: These methods should be faster because they do the iteration on the C-side rather than the Ruby-side.