- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm still somewhat of a beginner, and I've been trying all morning to get my first event handler working, with no luck. I've been following this example code:
IExternalEventHandler handler_event
= new ExternalEventMy();
ExternalEvent exEvent
= ExternalEvent.Create( handler_event );
The external event handler class implements the actions I need to execute in a valid Revit API context:
class ExternalEventMy : IExternalEventHandler
{
public void Execute(UIApplication uiapp)
{
UIDocument uidoc = uiapp.ActiveDocument;
if( null == uidoc )
{
return; // no document, nothing to do
}
Document doc = uidoc.Document;
using( Transaction tx = new Transaction(doc))
{
tx.Start("MyEvent");
// Action within valid Revit API context thread
tx.Commit();
}
}
public string GetName()
{
return "my event";
}
}
I can raise the external event from another thread like this:
exEvent.Raise();
Which is posted here: The Building Coder: External Events and 10 Year Forum Anniversary (typepad.com)
But I can't get it to compile. It doesn't seem to recognize the Class "ExternalEventMy" on the very first line of the code.
I'm trying to run this with the Macro Editor, and I thought all the code for the class ExternalEventMy should go in the main module, just after the startup regions. But that gives a "Namespace can not be found" error message.
So I tried to put it in with the Window1.xaml.cs, but then the compiler gives me a "Non-static field" error.
I've included a couple of screen shots and a zip of the .sln file. Any help would be appreciated. I'm trying to trigger this event from a WPF window, if that makes any difference.
Solved! Go to Solution.