@dale Would it be possible to add more user data types ala rs.setUserText()?
I use rs.SetUserText() to add configurable values to the objects we make.
(And then run an update script that reads these values, regenerates the geometry and replaces the original)
I would love to have a rs.SetUserBool() and rs.SetUserList() where:
rs.SetUserBool() would give us a toggle button and where
rs.SetUserList() would give us the option to choose from a list of predefined values.
Or a simpler version:
Let rs.SetUserText() accept True and False and if those are present show a toggle instead of text:
Instead of sticking to rhinoscriptsyntax you could venture into directly using the UserDictionary property on GeometryBase Class, which is essentially what setting a user text will be using.
Thanks for trying Nathan, but I am afraid I am way to low level for this⌠I donât understand how to use obj.Geometry.UserDictionary.Set(âFeatureâ, True)
Here is what I tried, and from here I donât know how to search for a solution.
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
# Select object
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select object")
go.SubObjectSelect = False
go.GroupSelect = False
go.GetMultiple(1, 1)
if go.CommandResult() == Rhino.Commands.Result.Success:
print go.CommandResult()
obj = go.Object(0)
### Here is where I fail...
obj.Geometry.UserDictionary.Set("Feature", True)
I find Python so much easier for my brain to use, so could you please try to explain why setting up obj the way I did was wrong?
I presume I should venture into the GeometryBase Class somehow, but this is too abstract for me to understand (And I must admit that I fear that if I start making too complex stuff I will suffer when maintaining it in the future, as using the tools are my main focus, not programming⌠)
OK, that was a long way to a destination unknown
I didnât get results I understood with TryGetBool so I used a Try Except solution instead. This now works:
But it doesnât show up in the userText panel in Rhino, so I am kind of back where I started, unless there is something else I donât understand yet (frankly I must say I donât understand what I have done so far either )
To recap the initial question:
Is it possible to add a True/False toggle to UserText?
Thanks Roger!
That works fine, it toggles as it should now. But (sorry for the noob question) but this attribute isnât available through any standard panels like UserText is it? I understand I can make my own GUI though, but I would prefer not to if I can avoid it.
I think the way you want it is not possible. If you look inside the âSetUserTextâ code, itâs simply:
obj = rhutil.coercerhinoobject(object_id, True, True)
if type(key) is not str: key = str(key)
if value and type(value) is not str: value = str(value)
if attach_to_geometry: return obj.Geometry.SetUserString(key, value)
return obj.Attributes.SetUserString(key, value)
Note the last line, obj.Attributes.SetUserString(key,value). Again, adding the data to the attributes of the object(note that object and geometry in rhino is not the same).
Now if you look into the rhino common namespace/object attributes class you can see that there exist a seperate method âsetusertextâ to explicitly set user text. Meaning, the userdictionary where you can add your bool types and the usertext are different(otherwise why not use the set method of the user dictionary).
Also, if you look into the python method above, you can see that in the second line the code checks if the value to be entered into the value-field is a string(text object) - if not, it will convert it.
So, what you want is not possible in that way, you have to use your own panel.