Background Process API Access?

Background Process API Access?

Kevin.Lawson.PE
Advocate Advocate
984 Views
2 Replies
Message 1 of 3

Background Process API Access?

Kevin.Lawson.PE
Advocate
Advocate

Is there any way to create a “Background Process” through the Revit API?  Such as when you run a “Systems Analysis”?

 

Ideal workflow:

  1. User Clicks a button in the current document. The background process starts and gives control back to the user.
  2. The background process starts that creates a new document, links in the current document, and performs API tasks in the new document, saves and closes the new document.
  3. When the tasks are completed, other API tasks are performed in the current document (nice, but not necessary, I can get around this requirement).

If this isn’t accessible through the API is there another way to do this through Autodesk Platform Services (Forge) or something?

KevinLawsonPE_0-1683053315979.png

 

-Kevin Lawson, PE
www.rippleengineeringsoftware.com
Revit heating and cooling load calculations in one click!
Accepted solutions (1)
985 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni
Accepted solution

Dear Kevin,

   

What you describe is completely impossible, if you take it word by word, because the Revit API and the interaction between Revit.exe and the API is single-threaded. All Revit API interaction requires a valid Revit API context, and that is only provided by Revit itself, and only within an event handler callback function such as the external command Execute method. So, no API interaction in a background process:

  

  

But: the workflow you describe can very well be achieved anyway, more or less, depending on how much background processing you require, and especially how much of that background processing is really heavy-duty Revit API interaction. 

  

You can run any and all non-API interaction in the background with no problem. Then, when that is completed, you can switch back into a valid Revit API context by setting up an external event. External events are the key for interacting between a non-modal context (your background process) and the modal Revit API context.

  

Lots of examples are given by The Building Coder:

  

  

Next: can this be achieved with APS, the Autodesk platform services (formerly Forge)?

  

Yes, absolutely. Using the APS Design Automation for API, you can automate any and all Revit API interaction that does not require any interaction with the Revit UI. To prepare for such a step, you can split your existing Revit desktop add-in into two parts:

  

  • One part referencing RevitAPIUI.dll and implementing the UI 
  • One part not referencing RevitAPIUI.dll, only RevitAPI.dll, using only the DB part of the API

  

The latter part can be migrated to APS Design Automation. Here are some examples of that process:

  

  

Good luck and much success,

  

Jeremy

  

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

Kevin.Lawson.PE
Advocate
Advocate

As always, thank you!  It looks like it's time to start digging into APS.

-Kevin Lawson, PE
www.rippleengineeringsoftware.com
Revit heating and cooling load calculations in one click!