Monday, October 22, 2012

Debugging Revit API Program

In order to debug your Revit API program using visual studio 2010 (for debugging with C# express see here) you need to follow these steps:

  • Go to your code in Microsoft Visual Studio 2010. In the Solution Explorer window, right click on the project name and choose properties of your C# project.

  • In the properties window select debug tab. In this tab, under Start Action part select "Start External Program". Use browse button and find Revit.exe where you have installed Revit. It should be in path like this:
                                  C:\Program Files\Autodesk\Revit 2013\Program\Revit.exe

  •  Go back to your code and add some Break Points beside the lines that you want the debugger to stop in your code. You can do this in two ways: 1) By clicking at the Gray area beside the line of the code you want the debugger to stop there. 2) Go to the line of code you want the debugger stop there, and from debug tab select Toggle Breakpoints(F9). Your code will look like this after adding break points.

  •  Now you are ready to debug your code. Click on the debug button (F5-Start Debugging). It makes Revit to open up, and you can open the project you want to work on in Revit now. Also, you can create a new Revit Project. 
  • In your Revit project, go to Adds-In tab and run your plug-in. It goes through your code step by step and stops at the lines that you have your first break point. Now you have the option to have a look on your code step by step and check the parameters and solve the problems you have. You can use Step Into, Step Over, and Step Out buttons to go through your code.

No comments:

Post a Comment