简体   繁体   中英

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,

You can look a the Revit SDK sample Events/EventsMonitor . It shows you how to subscribe to many Revit events in C#, including ViewActivating . The subscription mechanism and functionality is identical in all .NET languages.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM