RhinoCommon - Removing User Data

@stevebaer put together this great sample on how to add user data to an object using RhinoCommon.

http://wiki.mcneel.com/developer/rhinocommonsamples/userdata

How can I remove the data that was added?

It looks like I got started with writing a “Remove” function and commented it out; probably because it didn’t work quite right and no one had asked for it. I’ll look at this again and see if I can add it for SR6

I just committed code so SR6 will have a Remove function to let you remove the user data from an object.

Thanks!

Hi Guys, I was rattling my brain trying to figure this one out. Any way this can be implemented in Rhino 5? This is the missing functionality for my add-in.

Thanks.

The function to remove user data as added to Rhino 5 SR6.

The current service release of Rhino 5 is SR10.

To remove user data, use UserDataList.Remove().

I guess my problem isn’t what I initially thought it was. Currently I’m using the .GetUserString and SetUserString to get and set additional attributes to objects. What I was trying to do is find a way to delete user strings. For some reason I assumed it was associated with UserData.

So my first question is, can I delete UserStrings? and how?
Second question, would using the UserDictionary yield the same results?

Thanks.

To remove a user string, pass in a null or empty string as the value, to SetUserString.

2 Likes

How do we clear the UserDataList??

If I have a mesh object with a userdata and then split it, both the split meshes have the userdata (which is not correct)

@HepChan,

not sure if this applies to you but if you do not want your user data (or user string) to survive geometric changes, you might consider to assign the data to the object geometry and not to the object attributes.

Also note the replies above about removing the UserDataList.

c.

@clement, the user data is in the geometry and not in the attributes

On the same note, is there a possibility to see all the items in the userdata??

Having the option to store userdata is great, but it would be good if we could have more help on it and the exposure of its contents.

I really need the possibility to wipe the userdata clean

Hm that sounds strange. I’m working with many UserTexts (UserString) and Geometry.UserDictionary which holds various things like Numbers and geometry as ArchivableDictionary, with both i can reproduce that the data gets lost if i use _Split or _Explode. How do you store your user data ?

You’ll probably need to implement your own viewer. What kind of user data do you store and how ? Can you post a file with an object holding your data ?

c.

create a mesh.
Add userdata to the mesh as in http://developer.rhino3d.com/guides/rhinocommon/plugin-user-data/
Split the mesh.
both the meshes will have the userdata.

Hi @HepChan,

When user data is added to something, Rhino tries it’s best to make sure the user data survives object modifications. In the case of the Split command, any user data attached to the source object will be copied to the split pieces upon successful completion of the command.

If you have user data on an object and you want to remove it, use can call UserDataList.Remove. Note, you can only remove user data that you add - you do not get to remove user data added by other plug-ins.

Hope this helps.

– Dale

Hi Dale,

it seems to behave differently when i add an ArchivableDictionary containing some curve geometry to rh_obj.Geometry.UserDictionary via python. Every use of _Split purges the UserDictionary over here. Same goes for Strings attached to the geometry using SetUserString.

The latter can be quickly proved using the Rhino command _SetUserText with the _AttachTo=Object option. I’ve tested this in V5 only.

c.

That very well be. When I refer to user data, I am referring to classes that inherits from Rhino.DocObjects.Custom.UserData.

– Dale

thanks @dale.

After a runcommand, the user data of the rhino objects is modified.
On undo, the new userdata is still present in the rhino objects.

How can the userdata of the rhinoObjects be handled on Undo?

Sample code using UserData would be helpful.

To support undo, your command must make a copy of either the geometry or the object’s attributes, attached the user data to the copy, and then call either ObjectTable.ReplaceObject or ObjectTable.ModifyAttributes.

Here is a sample:
https://github.com/mcneel/rhino-developer-samples/tree/master/rhinocommon/cs/SampleCsUserData

– Dale

1 Like

This is great!! Thanks @dale.

just to confirm, the OnUndo event is not required to handle UserData. Am i right?
public static void OnUndo(object sender, Rhino.Commands.CustomUndoEventArgs e)

Correct, you do not need to listen to OnUndo events…

– D