mainly replaceObject.
you can check wether the old Object is “yours” and then transfer data to the new object.
Maybe you have to do this in a later step, subscribing to the rhinos Idle event and set a flag for some user-data-transfer.
it should be quite simple to compare two polylines.
with this you can also inform the user - the last command destroyed a “mike’s smart object”… do you want to go back / proceed…
(for example if fillet got applied and it is no longer a polyline-style)…
you might need to subscribe to further events to make undo / redo work of filter some special cases
I think this largely depends on how you want edits to the polyline to be handled, if the polyline is split, exploded, appended to, edited. I’d consider every possible way a curve could be edited.
I think generally for this kind of thing, having a custom document where you store your custom Objects is good, and ideally in this case you’d want some kind of ObjectProxy (or proxies) that wraps the Rhino Object so you can work with it however you like. Your Proxy (or proxies) can then interpret the curve and cache information about it and decide how to update those interpretations given the events.
If you explode the curve, you’d just create new proxies and remap your objects, which would be easier than creating/deleting new objects, and also ensure you don’t lose data, and also likely be easier for undo/redo stacks.
A novel idea that might help with things such as fillets or other inter-curve changes (that work for any kind of curve) might be to tie these proxies to the Domains of each segment rather than points, or sub-curves. Then if less than half of the domain of curve is changed, such as filleting a small radius between two segments, you could with decent certainly shorten the existing “wall” objects slightly to match the original 2 curves and create a new object for the fillet.
Considering other operations, explode would create new proxies, and your existing objects are unchanged. Changing a point would requite an update to the proxy domains. Join would merge 2 proxies and do a small amount of remapping.
I think something like this would work fine.
C#
public record struct MyProxy(Interval Domain, Guid RhinoObject, Guid CustomObject)
python
from dataclasses import dataclass
from uuid import UUID
@dataclass
class MyProxy:
Domain: 'Interval'
RhinoObject: UUID
CustomObject: UUID