UserData OnDuplicate triggered when selecting

Hi,
When I have some object with some UserData attached to it, the OnDuplicate method is called by simply selecting the object. Is that a normal behaviour?

Sample code:

protected override void OnDuplicate(UserData source)
        {
            RhinoApp.WriteLine("---- OnDuplicate ----");
            base.OnDuplicate(source);
        }

In Rhino:

Thanks in advance!

Unfortunately, the behaviour of OnDuplicate() doesn’t make any sense to me…
Let say I’ve one ‘Density’ field in my custom UserData and I want that field to be multiplicated by 2 on each object duplication:

protected override void OnDuplicate(UserData source)
        {
            RhinoApp.WriteLine("---- OnDuplicate ----");
            if (source is CustomData other)
            {
                Density = other.Density * 2;
            }
            base.OnDuplicate(source);
        }

Then comes the weird behaviours:

  • When I select the object in Rhino, the message “---- OnDuplicate ----” is prompted on the console, and in debug breakpoint mode, the Density field is indeed doubled BUT, the object UserData in the model does not appear to be modified. So far so good as it is not supposed to, but why the OnDuplicate is only partially executed then?

  • If I move the object, e.g. with the Gumball, the OnDuplicate is also called as well, but this time, the Density field gets multiplicated :thinking:

Any explanations welcome…

Hi @jeffoulet,

Does this happen on with other object types, or just extrusion (which I can understand).

– Dale

Hi @dale,

Thanks for coming back.
I tried with a curve and a point object, and the same behaviour is observed:

  • OnDuplicate partially run by selecting object (RhinoApp.WriteLine(’<message>’) displayed but no change of UserData fields)
  • OnDuplicate gets executed by only moving the object (Density field get also doubled).
    Shouldn’t it be the case only as the object is really duplicated, for instance with ‘Copy’ command or ‘Alt’+Gumball drag?

image