How to store data in rhino file?

Hi I am working on a script where I need to store some data in the Rhino file, how do I do that?

I don’t want to use “notes” if I can prevent that.

Thanks!

There is a StringTable on the RhinoDoc that you could use.

scriptcontext.doc.Strings.SetString("Hi" ,"There")

Thanks, I’ll look into it!

Well I looked into it… but I could not figure it out.

I did this

import scriptcontext as sc

StringTable1=sc.doc.Strings.SetString("Hi" ,"There")
StringTable2=sc.doc.Strings.SetString("There", "Hi")
print StringTable1
print StringTable2

And that prints:
There
Hi

And if I tried to call the StringTable1 and StringTable2 from another script then it returned nothing.

So can you point me in the even righter direction? :wink:

Are you just trying to store some text in the file? I think SetDocumentData() and GetDocumentData() are easier:

import rhinoscriptsyntax as rs
rs.SetDocumentData( "Jorgen's Place", "Favorite drinks", "Beer" )
data=rs.GetDocumentData("Jorgen's Place", "Favorite drinks")
print data

If you want to use docstrings, you can do this:

import scriptcontext as sc
sc.doc.Strings.SetString("Favorite drinks", "Beer" )
data=sc.doc.Strings.GetValue("Favorite drinks")
print data

–Mitch

What am I missing here?
It looks like you are typing the same data in rs.GetDocumentData as you type in rs.SetDocumentData (well, only two of the three items).
It seems to me that if you are storing something for later retrieval, you would not necessarily know what the contents is to be able to ask for it by contents.

To store, there is Section, Key, Value. To retrieve, you query the Section, Key, which returns the Value. It’s basically a dictionary. The difference is that you can have different dictionary sections, so it’s actually like a collection of dictionaries.

You need to know what you’re looking for if you want to find it… Do you always hit the “I feel lucky” button in Google? :smile:

–Mitch

Sweet, that works fine and is easy to understand!
Thank you!

Thanks! I think I’ve got it now. I could have looked it up in the help, but I wasn’t on my Rhino machine.

Nah, your just as lazy as the rest of us! :wink:

hi helvertosaur
do you know how to have a list of all the keys of the document? i’m refering to the keys of the userString on objects attribute.
and… after having that list, do you know how to find all the values related to a specific key

I think what you want is rs.GetDocumentUserText () - if you do not supply an argument it will return all the user text keys in the document.

If you have text stored on individual objects, you will need to use
rs.GetUserText (object_id, key=None, attached_to_geometry=False) and iterate through all your objects… Check the help for this item for more details.

–Mitch

ok thank you very much
an other question:
why i cannot iterate this:
objsId = rh.RhinoDoc.ActiveDoc.Objects.GetObjectList(rh.DocObjects.ObjectType.AnyObject)
this doesn’t give me a list but an 'EnumeratorWrapper’
do you have some suggestion?

Use rs.AllObjects()?

right! i ignored that command!
thank you again
i will iterate throught all the objects!
it’s strange there are not so many commands about objects key/value attribute.
usertext on objs is really intresting.
i want to do this command: