pythonironpythonrevit-apipyrevit

Revit API events with pyRevit


I'm trying to use the revit api events on my iron python addins (using pyRevit to add the ribbon and pushbuttons) but I don't really understand what to do.

I found this piece of code but I couldn't make it work. For starters, I'd like to print "View activated" each time a view is activated

https://github.com/eirannejad/pyRevit/issues/201

from System import EventHandler, Uri
from Autodesk.Revit.UI.Events import ViewActivatedEventArgs, ViewActivatingEventArgs

def event_handler_function(sender, args):
   # do the even stuff here

# I'm using ViewActivating event here as example.
# The handler function will be executed every time a Revit view is activated:
__revit__.ViewActivating += EventHandler[ViewActivatingEventArgs](event_handler_function)

Thanks,


Solution

  • have you checked the latest documentation?

    According to the wiki, you just need to create a .py/.cs file under a folder named hook and name the file as the event you want to use.