Optimize __CustomGetObjectEx in selection.py

(Willem Derks) #1


I found rhinoscriptcontext.GetObjectEx() to be slow when setting the allowed objects.
There is an annoying delay between the clicking and selection of an object.
After some digging and testing the method below (from selection.py) is noticeably faster when testing for containment (last 2 lines) than the iteration and equality test(current implementation)

class __CustomGetObjectEx(Rhino.Input.Custom.GetObject):
    def __init__(self, allowable_geometry):
        self.m_allowable = allowable_geometry
    def CustomGeometryFilter(self, rhino_object, geometry, component_index):
        #for id in self.m_allowable:
        #    if id==rhino_object.Id: return True
        #return False
        if rhino_object.Id in self.m_allowable: return True
        return False