Today the moon is full. I celebrated it last night already, sitting with a friend and having a fire on a hill with a 270 degree view to the east, west and south. Very beautiful!
This full moon is special, because it is the occasion of the Chinese Mid-Autumn Festival. It "parallels the autumnal equinox of the solar calendar, when the moon is at its fullest and roundest".
This Chinese festival will even be celebrated in Switzerland tonight, as the Mondefest Basel 2011, to honour the city partnership of Basel and Shanghai.
Back to the Revit API, here is a question that keeps cropping up again and again, prompting a summary of some basic aspects of interacting with Revit from a modeless form or external application, with an overview and pointers back to some of the previous posts and samples concerning this.
Question: How can I interact with Revit from a modeless form or external application? I need to be able to switch back and forth between Revit and my form without closing it.
Answer: The Revit API is entirely designed to work only within pre-defined call-backs issued by Revit.
Therefore, you can only keep your form open while continuing to work in Revit in either one of two ways:
The reasons and more background information on the current situation are given in the discussions of asynchronous API calls and idling, modeless door lister flaws, and the further posts that they point to.
As explained there, you cannot make use of the Revit API from an external application or a modeless context.
However, the API also provides the possibility to implement a workaround for this limitation, the Idling event. It enables you to drive Revit from outside indirectly by posting an event to your Idling event handler, which has full access to the API and complete read and write access to the entire application object and all its documents.
To use this, subscribe to the Revit Idling event and raise a signal from your external application or modeless dialogue. In the Idling event handler, check for the raised signal and execute whatever functionality you need. How this can be done is demonstrated and described in full detail in my sample to display a live webcam image on a building element face.
Another example, where Revit is driven from a modeless dialogue box, e.g. from a context outside of any Revit API call-back, also using the Idling event to "get back in" to the Revit API context, is given by my modeless loose connector navigator sample.
The original version was written for Revit 2011. I recently updated and improved it for Revit 2012 as well.
Additionally, a generic pattern for this process is described in pattern for semi asynchronous idling API access.
Unfortunately, like any other call-back, Idling costs time and should therefore obviously be used with great care. Use it sparingly and cautiously.