I’m writing a command that selects two sets of breps. The sets are supposed to be mutually exclusive (can’t pick a brep in set 1 to be part of set 2). I can’t seem to make this happen by using the available options in rs.GetObjects. What gives? Is there a way to do this without RhinoCommon?
import rhinoscriptsyntax as rs
set1 = rs.GetObjects("Select some breps for set 1",filter=16,select=True,preselect=False)
#set 1 should be selected now...
set2 = rs.GetObjects("Select some more breps. Shouldn't be able to pick any of the set 1 breps.",filter=16,select=True,preselect=False)
import rhinoscriptsyntax as rs
def GetTwoSetsOfObjs():
all_selectable=[obj for obj in rs.AllObjects() if rs.IsObjectSelectable(obj)]
if not all_selectable: return
msg1="Select some breps for set 1"
set1=rs.GetObjects(msg1,filter=16,preselect=False,select=True)
if not set1: return
#set 1 should be selected now...
still_selectable=[obj for obj in all_selectable if not obj in set1]
msg2="Select some more breps"
set2=rs.GetObjects(msg2,filter=16,select=True,objects=still_selectable)
print "{} selected objects in set 1".format(len(set1))
print "{} selected objects in set 2".format(len(set2))
GetTwoSetsOfObjs()
Personally I like to do it the following way by temporarily locking the first set, so the user has a visual clue which objects have been already selected for the first set.
import rhinoscriptsyntax as rs
def GetTwoSetsOfObjs2():
type_filt=16
msg1="Select some breps for set 1"
set1=rs.GetObjects(msg1,filter=type_filt,preselect=False)
if not set1: return
#lock set1
rs.LockObjects(set1)
msg2="Select some more breps"
set2=rs.GetObjects(msg2,filter=type_filt,select=True)
#unlock set 1 immediately afterwards
rs.UnlockObjects(set1)
if not set2: return
print "{} selected objects in set 1".format(len(set1))
print "{} selected objects in set 2".format(len(set2))
GetTwoSetsOfObjs2()
Thanks. For completeness: would you have an example kicking around of how to do this in RhinoCommon? I can’t seem to make it work purely by changing the get object properties.