algorithmic modeling for Rhino
#fridayNight
list = []
for obj in ghdoc.ActiveObjects():
if obj.ToString()=="Grasshopper.Kernel.Special.GH_ValueList":
list = obj.ListItems
lefts = []
for item in list:
lefts.Add(item.Name)
a = lefts
this version will only look at a value list that's actually plugged in to your python script:
list = []
for obj in ghdoc.ActiveObjects():
if ghenv.Component.DependsOn(obj):
try:
list = obj.ListItems
except:
pass
lefts = []
for item in list:
lefts.Add(item.Name)
a = lefts
Oops I broke it when I saved it as a user object.
Runtime error (MissingMemberException): 'list' object has no attribute 'Add'
Fixed it by adding "import Grasshopper" on line 1.
Userobj attached.
What would be interesting would be to limit the output to the selected list index.
Is there a method for the object, like ListItems, that would extract the currently selected index from the component?
Basically I want to be able to use the Value List component as a Key/Value search component because it's a better interface.
Man, someone should really work on some custom UI stuff for Grasshopper...
Hey Brain,
I did some tinkering and found you can call 'SelectedItems' on your obj which will return a list of the currently checked keys. You can use this to get the index(s) that are selected by comparing it to your 'ListItems'.
selectedKeys = [item.Name for item in valList.SelectedItems]
keys = [item.Name for item in valList.ListItems]
values = [item.Value for item in valList.Values]
You should be able to put together a dict (key/value) from that.
*Note the values are a mixed bag as they come out as either GH_integers or GH_Numbers but shouldn't matter once you've assigned it to your component output.
Here's the user object.
Hi Brian,
I was searching for how to extract the data from the left side of the Value list and I bumped into your post here.
I have a more specific request as I only want to extract the current(or the selected/checked) value of the left side instead of all the left side values.
I personally don't know much about Python, so I thought I could use the power of all the smart brains on the forum here.
Could anyone help me with that?
Many many thanks in advance!
Hi Wenyao, that's the "Value List Selected Value" output shown in the image above, which is available in the *.ghuser download link above.
Hi Brian,
When I dragged the Wombat ghuser file in, it says The User Object could not be created as the base type is missing.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by