Hello all,
I am trying to work with ‘Attribute User Text’ via python in grasshopper.
I can get and set these Key and Value pairs with rhinoscriptsyntax as below,
My first question is, is there a way to do the same with rhinocommon?
I have managed to read the Values for existing Keys via Rhino.Runtime namespace, but this only seems to allow me to read values for existing Keys, rather than get and set Keys and Values.
Which leads me to my second question, I have looked at alternatives in rhinocommon and understand that I can get and set Keys/Values for UserString or UserDictionary in the code, but it seems these have nothing to do with the UserText values shown in the properties panel in Rhino, is that right?
Eg. working with the UserDictionary, can have no effect on the Attributes that are displayed in the Rhino properties panel?
All of this means I am wondering what the difference is between these three things (UserText, UserString and UserDictionary). And when and why to try and use which one. Im purposely not mentioning UserData, which appears even more complex!
I am quite confused by all of this but hopefully the questions come across in a clear enough way for someone to offer some advice, I would greatly appreciate it!
rhinoscriptsyntax / UserText:
import Rhino
import rhinoscriptsyntax as rs
scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc
k = rs.GetUserText(iGeometry)
v = []
for i in k:
v.append(rs.GetUserText(iGeometry,i))
scriptcontext.doc = ghdoc
Runtime / UserText:
import Rhino
v = Rhino.Runtime.TextFields.UserText(str(iGeometry),"TestKey1")
UserDictionary - setting Key/Value, not affecting Rhino object:
import Rhino
import Rhino.Geometry as rg
iGeometry.UserDictionary.Set("TestKey1",rg.Plane.WorldXY)
k = iGeometry.UserDictionary.Keys
v = iGeometry.UserDictionary.Values