We have had a lot of discussion lately on effectively loading and debugging Revit add-ins.
John Morse suggested a technique to be able

dynamically reload an already loaded add-in
for
debugging purposes, and we posted some

updates
on that yesterday.
We also had an internal discussion on how to effectively manage the many SDK samples.
As I have mentioned in the past, I use

RvtSamples
to
load all the existing SDK samples plus all the ADN and Building Coder ones.
The ADN samples include collections for the Revit API Introduction labs, tips and tricks, geometry, RME and RST.
That system is extremely easy to maintain and effective to use, because I have one single file which I reuse unmodified for all versions and flavours of Revit and never have to touch again once it is set up.

My colleague Joe Ye is a fan of a different approach using AddInManager, and provides another solution for reloading an add-in to debug it without restarting Revit.
Here is his explanation of its advantages:

I am surprised that you rarely use the great tool AddInManager.
Maybe you don’t know what I meant by saving me a lot of time.
I am pleased to share how to save time when programming for Revit.
It can save time in two scenarios:

  1. Load and run quickly:
    1. We often create samples for a developer query. After creating and compiling the code, Revit.exe may already be running. We often have a Revit.exe running, right? If not, just start it. I launch the AddInManager command in the External Tools drop list, click the Loading… button in the interaction dialogue, find the command in the commands list box, and finally click Run to start it.
    2. Why this saves time: there is no need to modify the Revit.ini file. Configuring Revit.ini file takes time and needs carefulness. No need to restart Revit.exe to run new external command.
  2. Quickly change code and run the revised external command again.
    1. If our already loaded external command doesn’t work as we anticipate, we need to change the code and test the command again. I often encounter this scenario. I think this it is the same to many developers. It is painful to close Revit, compile the revised project, restart Revit, open the target model file, and restart the external command. This process takes at least 2 minutes, for Revit takes time to start. If the model size is big, that takes even longer and requires patience. If we are working in a virtual machine, this is even more obvious.
    2. I have this solution to do it quickly. I first change the code (this cannot be avoided, :-), then change the assembly name in the current project properties application tab. I rebuild the project, click the AddInManager command in External Tools to show the interaction dialog, find and click the previous expired command, unload it and load the revised plug-in, find and click the revised command, click ‘Run’ to run the revised command. See the new result of new command. We can also debug the revised command by attaching the process to Revit.exe.
    3. How can this work? Revit thinks that the renamed plug-in is a new plug-in. It won’t reject loading the revised plug-in. So after renaming the plug-in, the new plug-in can be loaded successfully again.
    4. Why this save time: We avoid closing and restarting Revit and reload the testing model file, only need to click the three buttons to unload, load and run.

With this great tool, we can do all kinds of normal command test work, for instance code changing or debugging, without restarting Revit at all.
I often share this solution in the Chinese Revit API training.
Seems attractive, right?

Many thanks to Joe for this nice overview!


Comments

8 responses to “AddInManager”

  1. I have a stock installation of Revit 2010. I do not see AddInManager anywhere.
    How does one get AddInManager to appear in Revit?
    Thanks.

  2. Dear David,
    Sorry I was so slow in answering…
    The add-in manager is part of the standard Revit SDK, and you will find it in the ‘Add-In Manager’ subdirectory of the main SDK installation folder:
    Directory of C:\a\lib\revit\2010\SDK\Add-In Manager:
    2009-04-27 08:25 482,816 setup.exe
    Cheers, Jeremy.

  3. Winston Avatar
    Winston

    Very nice post. Finally got to use it after I found it in the RTM version of the SDK for 2011 (I was using the pre-release version previously and it wasn’t included).
    However, whenever I need to make a change to my code, I didn’t need to change the project name, unload the previously loaded dll and reload the new dll, as stated in the post. All I did was make my changes in my code, build it, and re run it using the AddInManager, which makes this an even better tool.

  4. Dear Winston,
    Thank you very much for pointing that out!
    Yes, this post was written before I was able to talk openly about Revit 2011 in public, which is why I had to keep quiet about the improved functionality of the updated version.
    Just as you say, the AddInManager now allows recompilation and dynamic reloading of an already loaded add-in, which should significantly facilitate some debugging operations, especially if they require setting up some complex context in the Revit project for testing.
    Cheers, Jeremy.

  5. Jeremy,
    The way I had been working on my add-ins (up until 2013) was this.
    • inside VB.net express
    • compile/ recompile the dll
    • within revit (already running), use add-in manager to load the dll and run the command.
    • discover bugs
    • fix
    • repeat
    I didn’t have to restart revit.
    (I don’t think I can do the attach exe method with express. I’m not certain and I’m out of my league on that. )
    Anyway, in 2013 this no longer seems to work. I can’t even get helloRevit to run from the add-in manager.
    I wonder if you have any input on why that might be happening?
    and/or
    If you are still using the add-in manager for 2013. Are you able to load and execute dll’s from the manager?
    …gregory

  6. Hmmm….I may have discovered something. Or possibly rediscovered (this feels a little familiar. I may be thinking of the issue where if one of the dll’s security is not set to full, then AM won’t work).
    It looks like you can’t compile your dll directly to the add-ins folder if you wish to run it from the add-in manager. It has to be a separate folder.
    …gregory

  7. Dear Gregory,
    Thank you very much for your notes.
    No, I had not noticed this change. I don’t use the AddInManager regularly myself. I just start Revit from the Visual Studio debugger, test, and restart if I have a need to edit and recompile.
    If I really needed immediate edit-debug cycles without restarting Revit, I would isolate the bit of code I am working on an move it temporarily to a SharpDevelop macro, then move it back to the external add-in when I finished.
    Does the compilation to a separate folder solve the issue for you?
    Congratulations and thank you for letting us know.
    Cheers, Jeremy.

  8. Thanks a lot for all these useful information, I’m starting now to code for Revit and your blog is like heaven!

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading