About UserData and it's connection to RhinoObject

Hello.

I’m making a plugin that attaches data to an Object (ClippingPlane in this case).
This data has property that I want to be unique amongst all the userdata instances.
If an object is being copied, I would like to change this property to some unique value.
The “OnDuplicate” method is called both on “move” and “copy” so I don’t know whether I should change this prop or not.
Is there a way to know the difference?
Also, is there some way to relate userdata to the object containing it?
I could add the object Guid to it but I’ll have the same problem with the OnDuplicate event.

Also, OnTransform doesn’t tell you which object the transformation is applied to.
I have to take some properties from the object geometry itself but can’t store it in a precalculated form in the userdata. (not easy to change it from the transformation matrix)

How should one go about this stuff?

Thanks

Hi @ruisantosfortes,

You might consider implementing user data by inheriting a class from UserData. It’s a bit more work than just using user strings or a user dictionary. But it can handle some events, such as duplication or transformation, for you.

For an example of how to implement custom UserData, see the SampleCsMobilePlane sample, which is included with the SDK Samples on GitHub.

– Dale

Hi Dale.
I already implemented that.
The thing is that I can’t find any way to distinguish when OnDuplicate is called when the object is copied or just moved.
I my case I wanted a “name” prop in userdata to change to a unique name for the new object.
Well…guess I’m being a little too picky.
Thanks anyway

Hi @ruisantosfortes,

As part of your user data, keep track of the owning object’s ID. When they don’t match, then you’ll know the object was copied, not moved.

– Dale

Does that involve scanning all object of that type at each call to OnDuplicate?

Hi @ruisantosfortes,

Yes, this is true. In this case implementing one of document event watchers would help. For an example of how to hook up event watchers, see the following sample.

https://github.com/mcneel/rhino-developer-samples/tree/6/rhinocommon/cs/SampleCsUserData

– dale