Why guid changes when definition modified

“ComponentDefinition.guid SketchUp 6.0+
The guid method is used to retrieve the unique identifier of this component definition. The guid changes after the component definition is modified and the component edit is exited.”

why. why… :slight_smile:

This is a known issue. The guid implementation wasn’t fully cooked…

1 Like

Old thread but since this shows up in the Google search results I wanted to make some clarifications. The ComponentDefinition GUID is SketchUp’s way of knowing if two component definitions are identical. If you make a component, copy it to another SketchUp model and copy it back to the first one, no new definition should be added. If you on the other hand modify the component before copying it back to the original file, SketchUp has to know it has changed and add its definition to that model as well (with a unique name).

There isn’t really an issue per se with this design, and it is in my view quite well designed because it does its job in such an elegant way that most people, even developers, don’t notice it. If anything is an issue it’s the lacking documentation of what the GUID is for, and the lack of a persistent ID as a separate feature.

I agree. I do not see any real issue here. The GUID work as the API designers intended.

It makes sense from a data perspective, but not from a human perspective. E.g. If you call your child “Marco”, but then they grow up, you still call them by their given name. They’ve changed, but the identifier needs to persist or we won’t know what to call anything.

It’s the Ship of Theseus problem.

Unfortunately because of this, if you want a “human”-style guid than you can expect to persist, you have to generate your own identifiers using e.g.


and save them to the component with set_attribute.

It’s not that kind of identifier. It was never intended for human consumption.

You can also create a temporary group and use it’s GUID, and don’t add any entities, … SketchUp will clean it up.

guid = Sketchup.active_model.active_entities.add_group.guid
my_defn.set_attribute( PLUGIN_KEY, "GUID", guid )

Or … use …

require 'securerandom'
my_defn.set_attribute( PLUGIN_KEY, "GUID", SecureRandom.uuid )

Note that there is a request for a persistent ID for the definition class already logged.
I’m not sure if they’ll make it change when the definition is modified though.
Weigh in on the API tracker issue if you care …