Can Rhino.Geometry *EventArgs class be overloaded with additional methods/properties, or I have to create my own class and OnSomething event, plus event handler?
This question is motivated by the fact that OnObjectSelected event does not have a property to give object’s guid.
Here is a working code sample you can study, have fun:
import Rhino
import scriptcontext as sc
import pprint
class selectionEventHandler:
# Initializer
def __init__(self):
# Enable the event handlers
Rhino.RhinoDoc.SelectObjects += self.OnSelectedEvent
Rhino.RhinoDoc.CloseDocument += self.OnCloseDocumentEvent
# Disables the eventhandlers
def Disable(self):
Rhino.RhinoDoc.SelectObjects -= self.OnSelectedEvent
# Selection eventhandler
def OnSelectedEvent(self, sender, e):
print "Following guids have been selected:"
pprint.pprint([obj.Id for obj in e.RhinoObjects])
# close document eventhandler to purge the sticky keys
def OnCloseDocumentEvent(self, sender, e):
enableDisableSelectionEventHandler()
# Enablde / Disable function function
def enableDisableSelectionEventHandler():
# check if there is already an eventhandler called selectionEventHandler
if sc.sticky.has_key("selectionEventHandler"):
# Delete the old handler
handler = sc.sticky.pop("selectionEventHandler", None)
if handler:
handler.Disable()
handler = None
print("selectionEventHandler disabled")
else:
# Create the handler
handler = selectionEventHandler()
# Add the handler to the sticky dictionary so it
# survives when the main function ends.
sc.sticky["selectionEventHandler"] = handler
print("selectionEventHandler enabled")
if __name__ == "__main__":
enableDisableSelectionEventHandler()
1 Like
Ah, I see, so it’s a list of objects and to get the Guid I need to *.Id it. I assume all objects that are selected.
Thanks a lot @lando.schumpich.