Get usertext in grasshopper

python
unhandled

#1

I have a few breps that has attribute usertext in them. I link those into GH and send them into a GHpython component. In there the rs.GetUserText() gives me nothing. What do I miss?


(Laurent Delrieu) #2

Hello
I think Grasshopper make a copy of the object for internal uses. It prevents bad uses from users. There are many discussions on this subject. So as object is duplicated there is no copy of useless information for Grasshopper (everything that is not geometry ?).
Instead you have to get object by reference. So use GUID as input. Here a very simple example. Could not be the best way as I discoverd it now


See discussions on this subject here



You can also use Elefront which uses a lot referenced object.
Edit :
A more generic code
Rhino.DocObjects.RhinoObject ee = doc.Objects.Find(id);
System.Collections.Specialized.NameValueCollection keyValue = ee.Attributes.GetUserStrings();
keys = keyValue.AllKeys;
List allValues = new List();
foreach(string key in keyValue.AllKeys)
{
allValues.Add(keyValue.GetValues(key)[0]);
}
values = allValues;

get user text.gh (7.4 KB)


#3

I was trying to duplicate what elefront does with my own python so there is no dependency but I guess it’ll have to be C#


(Laurent Delrieu) #4

I anwsered with C# because I don’t use Python. I have no idea if everything in C# could be replicated in Python, but documentation says that Rhinocommon is in C#, Python and VB. So it must be possible you stay in Python.


I prefer C# (same for VB) because I now make some dll to be used in my program. So I can put some complex calculation in one C# instead of having a “Spaghetti” definition …