User data owner guid returns null on Transform


I have a piece of ON_UserData attached to an object, and track its Transform. When it is transformed, I need to retrieve the guid of the object it is attached to, to update a plug-in variable.

I do like this (over @dale’s SampleObjectUserData):

bool CSampleObjectUserData::Transform(const ON_Xform& xform) 
ON_UUID ownerId = Owner()->ModelObjectId();
// Make some checks with ownerId
return ON_UserData::Transform(xform);

Though, ownerId always returns a null guid. What am I doing wrong? Is it possible to retrieve the owner’s guid?


Hi @Pablo_Garcia-Amorena,

If the Owner member returns a null pointer, then it would probably point to something that derives from ON_Geometry or ON_3dmObjectAttributes, not CRhinoObject. If you want to track backwards, from the user data to the Rhino object, then I suggest adding the guid of the owning Rhino object as a data member on your user data class.

– Dale

Another thing is that by default, ON_UserData is not copied when the object it is attached to is copied (e.g. through a transform). You can set the m_copy_count member variable to a value larger than zero to have it copied with the copied object.

I see. The problem with adding the id as a user data member is that when the object is copied its attached user data is copied, carrying the id of the old object. As @menno pointed out I indeed need to copy the user data among objects.


I fixed this by using instead a transform event watcher. It makes more sense when it comes to update plug-in variables :+1:


1 Like