Custom.UserData wiped when extending geometry

Hello fellow grasshoppers,

I’m encountering a frustrating issue with Rhino.Geometry.Curve objects losing their custom data upon modification, and I’m hoping to tap into the community’s expertise!

The Setup

I have a specific Custom.UserData class that I successfully attach to various Rhino.Geometry.Curve objects (e.g., lines, arcs, polylines) within my custom C# components.

The Problem

The core issue is that when I perform common geometric operations that modify or extend the curve, the resulting new curve object loses all of its previously attached Custom.UserData.

For instance, if I take a curve C1 with attached data, and then run an operation like C1.Extend(start, end) or create a new curve through an Offset, the resulting extended/offset curve C2 comes out clean, completely devoid of the user data that was on C1. It seems Rhino’s operations don’t automatically propagate the user data to the new geometry.

The Question

Does anyone have a robust method or recommended best practice for persisting or transferring Custom.UserData from an original curve (C1) to a new curve (C2) that results from a geometric operation?

  • Is there a method within the RhinoCommon API for curves that handles data copying during modifications?

  • Should I be explicitly retrieving the data from the old curve and reattaching it to the new one? If so, is there a reliable way to automate this transfer process across various curve modification methods?

Any guidance on how to manage this data loss gracefully, especially in the context of curve manipulation, would be greatly appreciated!

Thanks for your time and help!

Hi @Frusciante,

For simple curve duplication, this works:

TestFrusciante.cs (1.3 KB)

In general, we advise developers to store user data on the attributes of an object. In doing so, user data tends to survive “better.”

In your case, using methods such as UserData.MoveUserDataFrom and UserData.MoveUserDataTo might be helpful.

You could also just check your newly modfied curve and see if it has your data. If not, add it.

– Dale

1 Like

Thanks Dale! I’ll check this out.

I am kind of noticing that the UserData survives in a RhinoObject that has the same Guid, but different runtime serial number. Not sure currently how this works, but I’m sure it has something to do with the callstack and storing a snapshot for proper undo/redos, but somehow not passing the information correctly.