How to identify a component definition after change it?

For example, creating an instance of a definition, the definition’s guide changes. In my plugin, it needs to change definitions often. Changing instructions come from external server. How can the server identify definitions after modified? Thanks.

If you need a persistent identifier for any entity, you can use the persistent ID.

The GUID is the revision identifier and changes each time the component is altered.

Just tested. I added a few definitions, made some operations, the definitions were removed except one. I am wondering that Sketchup will remove empty definitions soon?

Removing empty definitions was an early design choice when SketchUp was built. With no way to select an empty component it made no sense to keep it in the model. Only when the APIs and outliner was added empty components could be selected.

Add an attribute to the definition you are trying to find again afterwards.

Have a look at Class: Sketchup::AttributeDictionary — SketchUp Ruby API Documentation

1 Like

Empty groups and definitions are auto-erased as SketchUp processes your code.
So always create empty containers just before you add entities into them, that way they are retained.

If you have to create a container earlier then add a temporary cpoint into its entities, then it won’t be auto-erased.
Keep a reference to that cpoint and later on you can erase it to tidy up…
But with a little forethought you can structure your code so that empty containers are avoided…

1 Like

I changed my code to avoid empty definitions created previously.

For persistent_id, it is available to definitions since 2020. It seems limited for my plugin to use on earlier SU. So, set_attribute is a good solution for me. Thanks alot.

1 Like