Hello,
Using Rhinoscriptsyntax with rs.SelectObjects() and unselectall it’s easy enough to get current selections from the Rhino Document for GH to reference.
However, I’m struggling trying to create a persistent “selection set”.
The functionality I’m after is that, if objects are selected in Rhino document and the user clicks one of the input buttons such as add, remove, or clear; the script will modify a persistent data list that stores the selected objects.
So lets say the list has 3 objects in in, I click a new object in Rhino and then the add button, I would like the persistent list to be appended.
If I choose one of the objects and click the Remove button, if it exists in the persistent list it should then be removed.
Lastly the clear button would completely clear the selection set list.
I realize similar functionality could be achieved with a generic data collection in GH but I’m after utilizing the Remote Control Panel/Grasshopper Panel to expose these as User Input Buttons to users that won’t be going inside the Grasshopper environment.
I looked into Named Selections in Rhino but that didn’t appear to have the functionality to remove/add individual items, only make new or delete existing sets.
I’ve researched sticky dictionaries, global params, other things but I’m stuck on how to achieve the persistency of data in gh Python.
The end result would be a component in GH with an output of objects in the SO output and the inputs are buttons that will be “Published” to the Remote Control Panel/Grasshopper Panel.
Thanks for the help and leads!
Here’s my code and gh file thus far:
import rhinoscriptsyntax as rs
Selection_Set = []
def get_ids():
if Selection_Set:
IDs = [str(obj) for obj in Selection_Set]
return Selection_Set, IDs
else:
return None, None
def add_selected_objects():
add_objs = rs.SelectedObjects()
if add_objs:
Selection_Set.extend(add_objs)
def remove_selected_objects():
rem_objs = rs.SelectedObjects()
if rem_objs:
for obj in rem_objs:
if obj in Selection_Set:
Selection_Set.remove(obj)
def clear_selection_set():
rs.UnselectAllObjects()
Selection_Set.clear()
ghenv.Component.Message = str(len(Selection_Set)) + " Objects Stored"
if E:
SO, ID = get_ids()
if R:
remove_selected_objects()
if C:
clear_selection_set()
SO = Selection_Set
selection_set_component_01a.gh (6.3 KB)