Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ExternalEvent

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
1207 Views, 4 Replies

ExternalEvent

Hi! I want to create ExternalEvent on button click. But I get exception: "Attempting to create an ExternalEvent outside of a standard API execution". When I checked the thread of the main window and the Command class, they were the same thread. What's the magic? I created the class for reseting event in Command class.

 

Tags (2)
4 REPLIES 4
Message 2 of 5
jeremytammik
in reply to: Anonymous

Look at the Revit SDK sample ModelessDialog/ModelessForm_ExternalEvent.

 

The Building Coder also shares lots of samples implementing external events:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.28

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 5
Sean_Page
in reply to: jeremytammik

I found this site to be exceptionally helpful when creating external event handlers.

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-...

Message 4 of 5
BobbyC.Jones
in reply to: Anonymous

You cannot call ExternalEvent.Create() outside of a valid Revit API context, and a callback from a button click is most definitely not a valid context.

 

What i do is create an instance of the IExternalEventHandler and call ExternalEvent.Create() from the IExternalCommand, or other valid context, and pass them to the viewmodel (or create them in the ViewModel contstructor if you're newing up the ViewModel in the IExternalCommand.  I prefer MVVM, if you do not then pass them to or create them where you're UI logic resides, a Controller, or directly in the Form, or wherever.  Then in your button click callback you pass necessary state info to your IExternalEventHandler and then call Raise().

--
Bobby C. Jones
Message 5 of 5
jeremytammik
in reply to: Anonymous

Dear Bobby and Sean,

 

Thank you very much for your very helpful input.

 

I added it to The Building Coder for future reference:

 

https://thebuildingcoder.typepad.com/blog/2019/09/extensible-storage-external-event-dll-and-pipe-fac...

 

I also made a local copy the of the knowledge base article, since it is marked as Revit 2016 and I worry about it getting lost otherwise.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report