I’m using Rhino.Input.RhinoGet.GetMultipleObjects with filters but if the user preselects objects, they are able to select objects that should be filtered out. This is fine - everything works and the script ignores those filtered-out objects, but they remain selected on screen at the end of the script and I want the screen to highlight only objects were actually filtered. How do I deselect the objects that should be filtered out? Or, how can I deselect everything and then select just the objects that were filtered?
The normal Rhino behavior if preselecting is allowed but some of the preselected objects do not match the filter criteria is:
If at least one of the objects does match the filter criteria, it leaves the others selected as well, or,
if none of the objects match, to unselect everything and force a post-selection.
Rhinoscriptsyntax GetObjects() does the same - but it uses a custom
What you can do if you want the preselected non-matching objects to be deselected is:
While still in the object getter function, unselect everything, then re-select the objects that were actually filtered. Below is an example:
import Rhino import rhinoscriptsyntax as rs import scriptcontext as sc def CustomGetObjs(prompt,g_filt=None,a_filt=None,c_filt=None,ps=True): go = Rhino.Input.Custom.GetObject() go.SetCommandPrompt(prompt) #allow preselected object go.EnablePreSelect(ps,True) #main object type filter if g_filt: go.GeometryFilter=g_filt #secondary object attribute filter if a_filt: go.GeometryAttributeFilter=a_filt #custom geometry filter - can be anything if c_filt: go.SetCustomGeometryFilter(c_filt) get_rc = go.GetMultiple(1,0) if get_rc==Rhino.Input.GetResult.Cancel: return if get_rc==Rhino.Input.GetResult.Object: #some objects match selection criteria #unselect all sc.doc.Objects.UnselectAll() #select only the objects that were filtered for i in range(go.ObjectCount): go.Object(i).Object().Select(True) return go.Objects() #planar closed curves def cp_crv_filt(rhino_object, geometry, component_index): return rs.IsCurvePlanar(geometry) and rs.IsCurveClosed(geometry) def TestFunction(): prompt="Select objects" gf=Rhino.DocObjects.ObjectType.Curve af=Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve result=CustomGetObjs(prompt,gf,af,cp_crv_filt) if result is None: return print result TestFunction()