Select objects by key/value

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

some body knows those commands?

I believe Davide’s question was answered…

yes, for the while i made this:

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)
1 Like

how can i post a script correctly?
my indent was disappeared

To get better formatting of your script on this forum, please read this:

Hi Davide
I hope ([enter link description here][1]

[1]: http://mkmra2.blogspot.com/2012/12/creating-graphical-user-interfaces-with.html) can help you