UserDictionary directly on Geometry


(Karol Wierzbicki) #1

Hi,

I was able to assign user dictionary to the geometry:

rhObject.Geometry.UserDictionary.Set(“key”, “val”);

and I can see, that dictionary contains this entry, however I can’t get it with use of

obj.Geometry.UserDictionary.TryGetString(“key”, out str);

Both rhObject and obj are of type RhinoObject. What do I do wrong?


#2

You can get it like this:

Dim objVal as string = obj.Geometry.GetUserString(“key”)

at least… that’s how it works over here :slight_smile:


(Menno Deij - van Rijswijk) #3

Make sure that rhObject and obj both point to the same object (compare ID and runtime serial number).

I can’t reproduce the problem no matter how hard I try…


(Karol Wierzbicki) #4

Ah, sorry, I didn’t mentioned, but this is c#, There is no GetUserString here, but I have a GetString().
Still it doesn’t solve my problem as I’m using it without knowing if object have a string assigned, or not. I am trying whenever event RhinoDoc.SelectObjects fires, and I have only one object in my scene.

Strange thing is, that I can see, that object have this value assigned (in the watch in VS), just it’s not taken out fom the method.


#5

I found this:

to set user text, attached to an object:
private void RunScript(bool bake, GeometryBase geo, string key, string val, ref object A)
 {
geo.SetUserString(key, val);
 if(bake){
 RhinoDocument.Objects.Add(geo);
 }
 }
 
to set user text, attached to an object's attributes:
private void RunScript(bool bake, GeometryBase geo, string key, string val, ref object A)
 {
 Rhino.DocObjects.ObjectAttributes att = RhinoDocument.CreateDefaultAttributes();
 att.SetUserString(key, val);
 if(bake){
 RhinoDocument.Objects.Add(geo, att);
 }
 }

to modify an object's userdictionary:
private void RunScript(bool bake, GeometryBase geo, string key, string val, ref object A)
 {
geo.UserDictionary.Set(key, val);
 if(bake){
 RhinoDocument.Objects.Add(geo);
 }
 A = geo;
 }
to retrieve a value from an object's userdictionary:
private void RunScript(GeometryBase x, string key, ref object A)
 {
 A = x.UserDictionary[key];
 }

Does this help?


(Karol Wierzbicki) #6

I didn’t intended to troll with this topic :slight_smile: but after restart of computer all went back to the order. Sorry for wasting your time.