Since i find the SelKeyValue command in Rhino not very efficient when comes to selecting objects with a specific key value combination I am wondering whether a simple Eto dialog can be used that will allow user to select via 2 dropdown menus (key and value) and then select the objects that satisfy the criteria.
Does anyone have created something similar already?
So I did the prototyping yesterday. For what I currently need this does the work.
Feel free to have a look at the script and further improve.
I believe this feature should have come natively in Rhino
"""A script to select objects based on the selected usertext key/value.
Script by g.syn"""
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext
import Eto.Drawing as drawing
import Eto.Forms as forms
class SelectObjectsUserTextDialog(forms.Dialog[bool]):
# Dialog box Class initializer
def __init__(self):
# Initialize dialog box
self.Title = 'Select Objects by UserText'
self.Padding = drawing.Padding(10)
self.Resizable = False
self.usertext_keys = usertext_keys
#Create dropdown box
self.m_combobox1 = forms.DropDown()
for k in self.usertext_keys:
self.m_combobox1.Items.Add(k)
self.m_combobox1.SelectedIndex = 0
# Create the default button
self.DefaultButton = forms.Button(Text = 'OK')
self.DefaultButton.Click += self.OnOKButtonClick
# Create the abort button
self.AbortButton = forms.Button(Text = 'Cancel')
self.AbortButton.Click += self.OnCloseButtonClick
# Create a table layout and add all the controls
layout = forms.DynamicLayout()
layout.Spacing = drawing.Size(5, 5)
layout.AddRow(self.m_combobox1)
layout.AddRow(None) # spacer
layout.AddRow(None) # spacer
layout.AddRow(self.DefaultButton, self.AbortButton)
# Set the dialog content
self.Content = layout
# Get the value of the textbox
def GetText(self):
DropboxValue = self.m_combobox1.DataStore[self.m_combobox1.SelectedIndex]
return DropboxValue
# Close button click handler
def OnCloseButtonClick(self, sender, e):
self.Close(False)
# OK button click handler
def OnOKButtonClick(self, sender, e):
self.Close(True)
def selectusertext(usertext_keys):
dialog = SelectObjectsUserTextDialog();
rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
if (rc):
selected_key = dialog.GetText()
return selected_key
def getusertextkeys(objs):
usertext_keys = []
if objs:
for obj in objs:
key = rs.GetUserText(obj)
if key:
if key[0] not in usertext_keys:
usertext_keys.append(key[0])
else:
pass
return usertext_keys
def getusertextvalues(objs, key):
usertext_values = []
if objs:
for obj in objs:
if key:
value = rs.GetUserText(obj, key)
if value:
if value not in usertext_values:
usertext_values.append(value)
else:
pass
return usertext_values
if __name__ == "__main__":
objs = rs.GetObjects("Select objects")
usertext_keys = getusertextkeys(objs)
selected_key = str(selectusertext(usertext_keys))
usertext_keys = getusertextvalues(objs, selected_key)
selected_value = str(selectusertext(usertext_keys))
rs.EnableRedraw(enable=False)
for obj in objs:
if rs.GetUserText(obj, key=selected_key) == selected_value:
rs.SelectObject(obj)
rs.EnableRedraw(enable=True)
Indeed I 'm missing the option to see the a list of the values of the selected objects that have the the same key.
The (varies) of the sceenshot below, doesn’t give much of insight tbh.
Especially when it comes to select objects that share the same key and a specific value this cannot be performed from this panel.
The selkeyvalue command does the job but this is a counter productive way (too much typing) when it is required to select objects with different key/values
Make sure you’re using Rhino 7. In v7 The first column icon describes key/value matches. Right clicking allows you to select or filter to matching key/value pairs based on what you’re after.