# Noob question #005: retrieving guids from objectsSelected event

**URL:** <https://discourse.mcneel.com/t/noob-question-005-retrieving-guids-from-objectsselected-event/80826>\
**Category:** Scripting\
**Created:** [March 25, 2019, 9:08am UTC](https://discourse.mcneel.com/t/noob-question-005-retrieving-guids-from-objectsselected-event/80826 "2019-03-25T09:08:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivelin.peychev](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ivelin.peychev/32/676038_2.png) [@ivelin.peychev](https://discourse.mcneel.com/u/ivelin.peychev)\
**Post date:** [March 25, 2019, 9:08am UTC](https://discourse.mcneel.com/t/noob-question-005-retrieving-guids-from-objectsselected-event/80826/1 "2019-03-25T09:08:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lando.schumpich](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/lando.schumpich/32/636282_2.png) [@lando.schumpich](https://discourse.mcneel.com/u/lando.schumpich)\
**Post date:** [March 25, 2019, 7:24pm UTC](https://discourse.mcneel.com/t/noob-question-005-retrieving-guids-from-objectsselected-event/80826/2 "2019-03-25T19:24:13Z")

</div>

hello @ivelin.peychev,

WIth OnObjectSelected you mean the selectObjects event: [https://developer.rhino3d.com/api/RhinoCommon/html/E\_Rhino\_RhinoDoc\_SelectObjects.htm](https://developer.rhino3d.com/api/RhinoCommon/html/E_Rhino_RhinoDoc_SelectObjects.htm) ?

If so, this event has a RhinoObjects property ([https://developer.rhino3d.com/api/RhinoCommon/html/T\_Rhino\_DocObjects\_RhinoObjectSelectionEventArgs.htm](https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_RhinoObjectSelectionEventArgs.htm) [https://developer.rhino3d.com/api/RhinoCommon/html/P\_Rhino\_DocObjects\_RhinoObjectSelectionEventArgs\_RhinoObjects.htm](https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_DocObjects_RhinoObjectSelectionEventArgs_RhinoObjects.htm))

And from a RhinoObject you can get the guid.  
Or are you using a different event?

---

<div class="post-metadata">

**Author:** ![lando.schumpich](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/lando.schumpich/32/636282_2.png) [@lando.schumpich](https://discourse.mcneel.com/u/lando.schumpich)\
**Post date:** [March 25, 2019, 8:17pm UTC](https://discourse.mcneel.com/t/noob-question-005-retrieving-guids-from-objectsselected-event/80826/3 "2019-03-25T20:17:17Z")

</div>

Here is a working code sample you can study, have fun:

```auto
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()
```

---

<div class="post-metadata">

**Author:** ![ivelin.peychev](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ivelin.peychev/32/676038_2.png) [@ivelin.peychev](https://discourse.mcneel.com/u/ivelin.peychev)\
**Post date:** [March 25, 2019, 9:13pm UTC](https://discourse.mcneel.com/t/noob-question-005-retrieving-guids-from-objectsselected-event/80826/4 "2019-03-25T21:13:48Z")

</div>

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.
