Select objects by key/value_
i’m writing a little script in python to manage user string.
-i want to create a selection list box of key/value:
example:
first listbox: all the keys of the active doc
----------listBox-------------
select on key:
“material”
“zone”
“type”
----------------ok-----------------
after clicking on the key: “material”, the items of the listbox will be all the values related to that key (eg. “material”)
--------listBox------------
select values of “material”:
-any-
“steel”
“glass”
“wood”
------------ok-------------
clicking by clicking the objects will be selected until i will click the buttom “ok” going back to keys in order to select others key/values or clicking again “ok” in order to get that selection.
i need some commands i cannot find:
getkeys list of the active document
getvalues list related to a key
import Rhino as rh
import rhinoscriptsyntax as rs
keys = []
values =[]
objsId = rs.AllObjects()
for i in objsId:
keys_i = rs.GetUserText(i, None, False)
if len(keys_i) > 0:
for k in keys_i:
value = rs.GetUserText(i, k, False)
if k in keys:
index_k = keys.index(k)
if not (value in values[index_k]):
values[index_k].append(value)
else:
keys.append(k)
values.append([value])
kList = rs.ListBox(keys, "Keys to select:", "Select Objs by Key/Value")
if kList in keys:
index_kList = keys.index(kList)
vList = rs.ListBox(["all"] + values[index_kList], "Values of " + kList , "Select Objs by Key/Value")
if vList == "all":
vList = "*"
if vList:
objs = rh.RhinoDoc.ActiveDoc.Objects.FindByUserString(kList, vList, True, True, True, rh.DocObjects.ObjectType.AnyObject)
rs.SelectObjects(objs)