RhinoCommon - Removing User Data


(Dale Fugier) #1

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

How can I remove the data that was added?


(Steve Baer) #2

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


(Steve Baer) #3

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


(Dale Fugier) #4

Thanks!


#5

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.


(Dale Fugier) #6

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().


#7

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.


(Dale Fugier) #8

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


#9

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)


#10

@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.


#11

@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


#12

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.


#13

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.


(Dale Fugier) #14

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


#15

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.


(Dale Fugier) #16

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

– Dale


#17

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.


(Dale Fugier) #18

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


#19

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)


(Dale Fugier) #20

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

– D