Thursday, April 22, 2010

Revit API 2011: Revit AddIn Manager – Almost Edit & Continue

(part of our ongoing series)
If you’ve been developing for Revit for a while – you groaned significantly when, in Revit 2010, changes were made to Revit that disabled the “Edit-and-Continue” capability within a Revit add-in. That is to say – if you wanted to make a minor code change while Revit was debugging – you had to close Revit (wait for Revit to be totally closed), perform the change, then restart Revit, re-load your model, and then try to get back to the same location. Argh – seems like 2+ minutes down the drain any time this happens.

Enter the “Revit AddIn Manager” – part of the Software Development Kit. This tool has been around since 2009, I think – it historically provided handy mechanism for a developer to test External commands or applications – even when they forgot to add them to the REVIT.INI file. It could both update the INI file for you, or even just launch the command in session.

image

What’s Different in 2011?

I suspect due to some conversations and posts that were had on Jeremy Tammik’s blog late in the development process, the AddIn Manager has been notably improved – such that while you can’t support edit-and-continue, you can now support updating your code while Revit is running, and just re-running your command inside of Revit.

How does this work? The Addin utility is doing some lifting behind the scenes, including copying the DLL and related files to a temporary folder, and loading the .NET assembly DLL from that location.

What does this mean for us? That when we start up Revit with the debugger attached, we can run the AddInManager. From the AddInManager we can launch our command in a way that loads it into memory before starting the debug process.

While we still cannot edit and continue, we CAN open a second copy of Visual Studio, and make changes by rebuilding the project.

- it allows us to overwrite the project, because the running project was copied to somewhere else.

- we are now able to just re-start the AddIn Manager in order to start our updated version of the command.

The Features of the AddIn Manager

The behind-the-scenes mechanics are described above. It also has (obviously) been enhanced to support the new “.addin file” mechanism rather than the Revit.INI mechanism of registering addins. The command also supports some additional options which can be a little confusing at first. The list of AddIn Manager commands looks like this:

image

What’s the deal with all this manual, automatic and faceless?

The Manual vs. Automatic entries refer to the new TransactionMode and RegenerationMode that must be assiged to each command. Because the AddIn Manager is going to invoke your AddIn, it would be a problem if AddInManager specified Automatic mode but your code specified manual mode. So you have to pick automatic or manual based on what YOUR command is defined as. NOTE: No mix/match on transaction and regeneration mode… you have to be either Auto/Auto or Manual/Manual. The application will stop you if you pick the wrong one (although the error message leaves something to be desired).

Faceless, while the mechanism seems a little clumsy – is a nice little feature. Fundamentally – it remembers the last command that you executed, and will just execute that again (no user interface, it just does it – that way you don’t need to re-browse, re-select, and re-run the command in question).

Conclusion

If you occasionally work with API developers – get a copy of the AddIn Manager to make it easier to test and setup API AddIns! If you’re a developer, there are now many good reasons to set up the AddIn Manager. So get to it! It’s in the Revit SDK installation folder.

No comments: