Debugging Commands in Revit 2010

by Guy Robinson 12. June 2009 16:31

Before I cover debugging… It looks like the classic UI is still with us. While this is encouraging as a short term solution and not totally surprising, I can’t see it being in Revit 2011 or above. With the API they’ll have to put back the toolbar code. Which means 3rd party developers will have to accommodate both solutions (ribbons, toolbars). Bit of a mess but then again so is the ribbon and I’m sure there will be many happy customers if they give us a choice until the messribbon is fixed.

Debugging in Revit 2010

I noticed from Ed’s post that he’s having problems debugging in 2010. There is nothing worse than having to continually restart Revit when editing standard API commands. Especially if you’re trying to test against a large project. And personally I never liked edit-continue as a solution, particularly if you’re a TDD/ R# fan.

There’s better but more complex solutions but here is a simple approach that allows you to quickly get up and running. The basis of the solution is running your code as a macro. To do this you have to target RevitProxy rather than RevitAPI. The Factory has been good enough to maintain the same namespaces between the 2 libraries. With the following exceptions.

  • You can’t implement IExternalCommand.
  • Generics aren’t supported so get_Elements(Filter, ICollection<T>) won’t compile.
  • No implement ribbon related methods.

So to use this technique you have to provide a certain level of code separation which isn’t a bad thing.

I’ve uploaded a test VS Project and a macro showing how to use it as a Document macro. To do a build/Run cycle if you modify this code you’re have to re-reference the project assembly in the VS project. The project just tests a simple utility class that counts the number of walls. So to debug using this approach. Modify and compile your  assemblies in Visual Studio. Now recompile the macro in VSTA and debug from VSTA. Not ideal but better than nothing.

So how to use this technique?

Create your project referencing the RevitAPI assembly as normal. Now create a second project in the same solution . This is the assembly that will be used in the macro and subsequent debugging.

In this second project add a reference to the RevitProxy assembly.

RevitProxyRef

Create your classes in the standard API project. Then the crux of this approach is mirroring these classes in the RevitProxy project. To do this go to the RevitProxy project and add the class by adding it as an existing item:

AddExistingItem

Then reference the file as a link rather than copying the file.

AddingAsLink

So what you should end up with is 2 projects that mirror the same classes you wish to debug.

CompleteProjects

Now fire up Revit 2010 and create a macro. Add a reference to the RevitProxy referenced assembly and implement the relevant code using your classes as you would in a RevitAPI command.

VSTAProject

Comments are closed

About the Author

A .NET software Developer providing custom applications and commands for architecture firms exclusively working with Autodesk Revit and integration with any associated applications. All from a little place north of Whitianga, New Zealand.

Page List

Disclaimer

I'm self employed so the opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway☺

© Copyright2008

Creative Commons License
Blog content is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

With the following exception. All code snippets, application and libraries are licensed under a a Apache License Version 2.0

Autodesk Revit®

Autodesk: Revit is a product that is wholly owned by Autodesk. Any reference to Revit,Revit API, Revit Architecture, Revit MEP or Revit Structure on this site is made acknowledging this ownership. Refer to Autodesk's own web site and product pages for specific trademark and copyright information. Autodesk represents a great many products and every attempt will be made to respect their ownership whenever one of these other products is mentioned on this site.