Question
What should I include in the startup and
shutdown methods: Module_Startup,
Module_Shutdown, Module_Startup,
and Module_Shutdown?
How and why should I register and unre-
gister my Revit event handler?
I have a dialog that does not seem to work
correctly and is causing issues with Revit.
I want to experiment with the Startup and
Shutdown methods and an event handler.
Can you show me an example?
VB.NET example, Application-level:
Answer
use this.Application or Me.Applic-
ation.
The Module_Startup method is called
a module loads and Module_Shutdown
is called when a module unloads. Module
Startup will be called only when the
corresponding tab is selected or when the
macro project is rebuilt.
Module_Startup is called when a Revit
project opens and Module_Shutdown is
called when the project document closes.
You can add your initializing code in the
Module_Startup methods and do the
cleanup work in Module_Shutdown
methods. For example, you can register
event handlers at start up and unregister
them at shutdown (which is the recommen-
ded way).
As noted previously, the recommended
way to do this in Revit VSTA is to register
event handlers in the *_Startup method
and unregister them in the *_Shutdown
method. Every VSTA macro will be loaded
and unloaded dynamically. When you de-
bug a macro, if the event handler is not
properly unregistered, Revit may call a
wrong method (maybe an invalid memory
address). Although Revit VSTA may prevent
Revit from crashing in this scenario, any
event handlers that are not properly unre-
gistered may cause performance issues
during your current Revit session.
Modeless dialogs operating outside the
scope of a running API callback may cause
problems. It is recommended that you
avoid such callbacks to prevent instability
in Revit.
The following sample code shows how to
register an OnDocumentNewed event
handler, which will automatically launch a
message box when a new Revit project is
created. Note: One of the VSTA samples
provided on the Revit SDK may show an
example of a document-level event hand-
ler's startup and shutdown. This FAQ shows
Application-level event handler examples.
Please note that 2010 events are not in-
cluded with Revit VSTA IDE 2010.
Revit Macros FAQ | 1447
Need help?
Do you have a question about the 256B1-05A761-1301 - AutoCAD Revit Structure Suite 2010 and is the answer not in the manual?