Unique Entity Id?

Hello, I want to get a unique id of each entity using SUEntityGetID() , but I found two componentInstance(created from the same definition) in a single model sharing the same id and pid, it that normal? And how could I get the unique id of them?

Yes, this is normal. The Entity Id is not unique from session to session.

By using the SUEntityGetPersistentID() function of the C API, or the Sketchup::Entity#persistent_id method of the Ruby API.

These persistent IDs are unique from session to session.

I think the question was a bit different.

EntityId / pid are not unique for entities in two different component instances because they are a part of the same component definition.

You’ll need to compute your own id to get unique id for any element in any instance.

You may also try to use InstancePath and persistent_id_path

Oh! You are correct. I missed the “and pid”. (My bad.)


Yes, a C function equivalent of the Ruby API’s Sketchup::InstancePath#persistent_id_path method would likely be promising.

I wonder why they did not include such a function in the C API?

Actually, there is a function for this:
(I missed somewhere that the original question was for CAPI)

SUInstancePathGetPersistentID(SUInstancePathRef instance_path, SUStringRef* pid)

1 Like

I still get the same pid using SUInstancePathGetPersistentID(). This is how I use it.

void ParseComponentInstance(m_instance_path, instance...)
{
	SUInstancePathPushInstance(m_instance_path, instance);
	SUInstancePathGetPersistentID(m_instance_path, pid);

	...

	SUInstancePathPopInstance(m_instance_path);
}