This actually can be done in python, though it may seem a bit unusual because it involve wiring up events that can be fired at any time and not necessarily in the scope of a single running script. There are many events in RhinoCommon that you can attach a callback function to. Here’s an example of having a function get called each time an object is added to the Rhino document.
import Rhino
import scriptcontext
def MyAddObjectEvent(sender, e):
print "Object Added, Id =", e.ObjectId
#check to see if the callback is already assigned
if scriptcontext.sticky.has_key("MyAddObjectEvent"):
print "removing the callback"
func = scriptcontext.sticky["MyAddObjectEvent"]
Rhino.RhinoDoc.AddRhinoObject -= func
scriptcontext.sticky.Remove("MyAddObjectEvent")
else:
print "adding the callback"
func = MyAddObjectEvent
scriptcontext.sticky["MyAddObjectEvent"] = func
Rhino.RhinoDoc.AddRhinoObject += func
If you run this script and then later add a line (or any geometry) to Rhino, the MyAddObject function will be called and will print out the Id of the object that was just added.