We are currently being flooded with questions about a topic that has already been discussed repeatedly and in depth in the past, external access to the Revit API.
Possibly, the cause is the growing interest in implementing web driven solutions to generate RFA and RVT files.
It is in fact possible to implement a web server driving Revit in the background to execute such tasks, as demonstrated by the old sample showing how to drive Revit through a WCF service and other examples listed in The Building Code topic group on Idling and external events for modeless access and driving Revit from outside.
However, this kind of access is currently unreliable, since Revit is designed for interactive use, not batch processing.
Furthermore, it is not supported by the Revit desktop product license.
If you are interested in official support for this kind of service, please share your requirements, thoughts and input on Revit I/O with us.
Future support for generating RVT
and/or RFA
files through a web service has already been announced as part of
the Forge
Design Automation API.
At present, the API provides the ability to run scripts on AutoCAD DWG
files, with plans in the works to expand to file types generated by other design software.
Current functionalities for DWG files include
Forge also already provides support for one RVT
specific operation in the cloud today that may be of immediate interest to you, via
the Model Derivative API; check out
the supported translation formats and
note that RVT
can be converted to DWG
and IFC
, besides the thumbnail and Forge-specific SVF
formats.
If your requirements to access RVT files from an external context are driven by the need to view the BIM, not modify it, Forge can probably cover all your needs right now.
Returning to the question of external Revit API access today, one of the latest incarnations of this kind of question is the Revit API discussion forum thread on how to load Revit file in API using C#, also asked on StackOverflow:
I want to make use of the Revit API in C# code.
I am trying to export images of specific views from a Revit project.
How can I access the ExternalCommandData
required by the Execute
method?
public Autodesk.Revit.UI.Result Execute( ExternalCommandData revit, ref string message, ElementSet elements ) { UIApplication uiapp = revit.Application; }
I want to browse *.rvt
files and call the above method from a Windows form.
You could very well make use of the Forge translation process and APIs mentioned above to achieve what you are asking for.
Revit itself, however, can only run plugins in-process, therefore you cannot use its API from an external WinForm app.
The Execute
method you mention is a call-back method, implemented by a Revit add-in external command in a .NET assembly DLL loaded by Revit and called by Revit in a specific context.
Revit creates and passes in the ExternalCommandData
information.
Calling directly into the Revit API from an external context yourself is, was and always has been illegal.
The Revit API cannot be used at all except within a valid Revit API context.
Such a context is provided exclusively by Revit call-back methods.
You need to subscribe to a Revit event, such as an external command Execute
method, and let Revit call it for you.
Within the event handler, the Revit API can be used.
You can also use the Revit API to set up an external event that can be raised from a non-Revit-API context, such as your standalone external application.
This is demonstrated by the ModelessDialog/ModelessForm_ExternalEvent Revit SDK sample.
For more information on the Revit SDK, please refer to the getting started with the Revit API learning material.
This specific question has been answered and discussed in depth numerous times in the past, both in the Revit API discussion forum and by The Building Coder.
Many examples and further explanations are provided in The Building Code topic group on Idling and External Events for Modeless Access and Driving Revit from Outside.
Here are some other recent Revit API forum discussion threads addressing similar issues: