Search code examples
multithreadingasynchronousrevit-apirevit

Revit API How to make a external command run asynchrously?


I have an External Command to create about 40 (or even more) Generic model in Revit. I want to make Revit run the command asynchronously to speed up the process according to this flow:

load command -> run command -> load families -> generate family instances asynchronously -> end command.

I 've read some ideas a bout make a modeless dialog to work around but it is not what I need. How can I do this?


Solution

  • Meiki is completely correct. The Revit API can only be used within a valid Revit API context, and such a context is provided exclusively by Revit events. You can however implement an external event and trigger that from outside to obtain access to a valid Revit API context. This is discussed in detail with many solutions provided by The Building Coder in the topic group on Idling and External Events for Modeless Access and Driving Revit from Outside.

    Another approach might be to make use of the DocumentOpened Event. You could use that to trigger the execution flow you desire.

    A third but unsupported approach might be to make use of a journal file, as in the IFC Import and Conversion Journal Script.

    I would start out reading the numerous solutions listed in the topic group, and probably end up making use of an external event.

    Good luck and have fun!