How to have my plugin running without freezing Revit

How to have my plugin running without freezing Revit

Anonymous
Not applicable
526 Views
2 Replies
Message 1 of 3

How to have my plugin running without freezing Revit

Anonymous
Not applicable

I hope I am not wording my question wrong, but I just can't find the answer to this.

I want that while my plugin is running and processing data, that the user can keep working on his project in Revit, how can I enable this?

0 Likes
Accepted solutions (1)
527 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni
Accepted solution

This is a good and valid question, and unfortunately a little bit tricky to implement. Not really tricky at all, but maybe a bit confusing for a beginner. 

 

The problem: Revit itself (mainly) and the Revit API (completely) is single-threaded. Therefore, as you observe, your add-in will block further execution. 

 

One way to break out of this is to let your add-in display a modeless Windows form, instead of the normal blocking modal dialogue. 

 

Once you do that, your add-in form will continue being displayed even after your external command that launches it has completed and returned to Revit. The user can continue working in Revit and still interact with your form.

 

However, now comes the next problem: because the Revit API is single-threaded, you no longer have access to it from your modeless form, which is running in a different thread.

 

This can be solved using an external event.

 

This may all sound scary but is in fact very simple once you get used to it.

 

Many solutions and explanations are listed in The Building Coder topic group on external events for modeless access and driving Revit from outside:

  

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

  

The Revit SDK sample to look at for this is ModelessDialog/ModelessForm_ExternalEvent.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks Jeremy for the insight!

0 Likes