Nuke all user text data on an object?

Is there a way to nuke all the keys all at once on a specific GUID using Python?
I know you can do it one at a time, but I don’t want to have to specify every key manually. I want to just feed the object ID into it and have a clean slate coming out.

Thanks in advance!

1 Like

Are you talking about UserStrings, UserDictionaries or UserData?

This works for rhino 6:

import rhinoscriptsyntax as rs
objects = rs.SelectedObjects(False, False)
object = rs.coercerhinoobject(objects[0])

# delete all user strings
object.Attributes.DeleteAllUserStrings ()

# delete all userdata (typically used by plugins)
object.Attributes.UserData.Purge ()

# delete the user dictionary
object.Attributes.UserDictionary.Clear ()

For rhino 5 it seems a bit more complex, you’ll need to iterate through the userdata, and userstrings

I am talking about Attribute User Text panel under properties, in rhino 6.
So I think I would need this one?

# delete all userdata (typically used by plugins)
object.Attributes.UserData.Purge ()

Can you point me to documentation on all 3 methods? I would like to read more on them to wrap my head around the difference.

Also, do you know if there is a way to have other Notes section inside of rhino file?
I need a place to store the same type of data as Notes section allows you (Multi-line) and pull it back up on specific layout pages…

Thank you!

Sure. The main point of entry would be the ObjectAttributes

From there:

The method DeleteAllUserStrings()
UserData Which points to a UserDataList
UserDictionary Which points to an ArchivableDictionary

Notes seem to be part of the document. Which probably means you can have one note per document.

arendvw,
Thanks for the source info.

In regards to the Notes, I just want to store the same type of data (multi-line text). It doesn’t need to be in the notes section, just needs to exist in the file.
I was trying to use the user attribute text on the object that I know will always exist in the file no matter what. But it only allows for single line string. Maybe there is a way I can cheat it? Use the user attribute text, make a key called “Notes1” and “Notes2” and somehow format the date in a way that regular text filed inside of rhino can display it as a multi-line?
Basically right now I use the Notes section for customer notes, I need another field/place like that for our shop department (internal notes).
If there isn’t a way to do that right now, would be a very useful feature in a lot of different ways.

Having an issue.
I have this

object = rs.coercerhinoobject(id)
id = object.Attributes.UserData.Purge()

inside of my for loop. where ID is GUID that’s coming from before.
if I print ID before the object = like I see the GUID
when I print it after the object.Attributes.UserData.Purge() i get None…
I have a command right after that makes a Bounding box around the GUID and it’s kicking out

Message: Could not convert None to a Point3d

As it’s not getting any guid.

Am I doing something very wrong?
When I just use the same lines of code as you posted before, I don’t get the errors, but it’s also not stripping the UserText…

Not sure if this is the best way to do it, but it worked for me. If anyone else needs it
id here is guid

# Check to see if there is user text		
if rs.IsUserText(id) == True:
	# If there is, get all of the keys
	allKeys = rs.GetUserText(id)
	# Loop over all keys to delete them 
	for k in allKeys:
		rs.SetUserText(id, k)
1 Like