Tuesday, November 15, 2011

[Revit API]– Revit Remote Boot - A technique to run an API add-in on a particular Revit model without user interaction

At last years Autodesk University, someone mentioned that they were looking for a way to run an export on their model once a day, on a schedule. This is not something that the Revit API is generally used for, but it  got me thinking of ways that I could make it happen. While flying around the USA after AU I hacked together some prototype code which did just this, but left it shelved. For my AU 2011 virtual class, I decided to finish it off and make it public, in case someone else wants to use it.
The program is called ‘Revit Remote Boot’, and is really more of a ‘system’ than a program, there are a number of moving parts to make it all happen. Put simply, it is a couple of interacting programs that allow you to perform an operation on a Revit model from a script.
Take a look at this video, which is a small part of my AU Virtual class, for a full demonstration of what it does. Note that while it talks about using Revit Server to create a local model, if you are running just a pure file server, this is fine as well – you could just directly open the file. It’s just that running Revit Server opens up some interesting possibilities and was the topic of my AU presentation.


Revit Remote Boot Demonstration from Rod Howarth
(you should head to the Vimeo page and watch it in high definition there to read the text)
Basically your application can save an xml file in a certain directory, which ads a ‘job’ to the queue. Then, using the RevitServerToolCommand, you can, from a batch file, create a local copy of the Revit Model you want to work on, and open it in Revit. From there, a Revit API add-in will detect that you’ve opened a model that corresponds to a job, and will run the other Revit API add-in that was specified in the job file. After this is done, the job is marked complete, and Revit is closed.
In my example, I’ve done a simple export to DWF of the model, the idea being you could set this up to run at 1am every night, and export the DWF model to a certain location – perhaps for viewing in Design Review on mobile devices. However, you could use it for any Revit API add-in. For instance, you could have a high powered server which you setup as a local Revit Server just purely to run this Revit Remote Boot. On this server you could create a job to run a structural analysis add-in, or other computationally expensive stuff. This way you can setup your own “cloud”, running Revit directly. You could also run certain audits on a model, for example, you could create an add-in that counts the number of warnings present in the model and saves this to a database, for displaying in a ‘hall of shame’ on your company intranet. Smile
This is highly experimental, and has some pitfalls, so should be considered as a proof of concept, rather than a production ready program. The main pitfall is that any errors that come up are shown as dialog boxes, and there is no easy way to deal with this in Revit. To get around this I’ve used AutoHotKey (http://www.autohotkey.com/) to detect certain dialogs and close them, but if there are unexpected ones, it will fall over.
If you are interested in the code behind this, check it out here: https://github.com/RodH257/RevitRemoteBoot you can use the ‘zip’ button there to download it if you don’t have git.
I’d love to hear your thoughts on this, and whether you think Autodesk should work towards making this kind of thing easier to do?

1 comment:

Barry Ralphs (BazzaCAD) said...

Wow, this is a really cool project.
Yes Autodesk should allow Revit to run in some type of 'batch' mode.
Do you think your system could do some type of unattended batch plotting?