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
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:
- Load and run quickly:
- 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.
- 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.
- Quickly change code and run the revised external command again.
- 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.
- 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.
- 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.
- 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!