"Start external program" option in Visual C# 2010 (Express)

posted Jun 11, 2011, 7:08 AM by admin@ revitviet.vn
In Revit SDK they use Visual Studio with the "start external program" option on the "debug" tab but it is not available in Express version (a free but not-so-powerful version of VS), you may need another way to hardcode this information into your program. if you were using VS Professional, this code would be generated automatically.
In the folder of the project file (.csproj), find the file YourProjectName.csproj.user (create one using the notepad if there is no such file), and edit the file as follows:
———-
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition=" ‘$(Configuration)|$(Platform)’ == ‘Debug|AnyCPU’ ">
    <StartAction>Program</StartAction>
    <StartProgram>D:\Autodesk\RAC10\Program\revit.exe</StartProgram>
  </PropertyGroup>
</Project>
———-
Remember to change the <StartProgram> item to the actual path of your Revit program
 
High-level procedure summary: (use it as a check list if you want)
1. project: create a new "class library" type project in VC# (therefore a .dll file will be created instead of a .exe stand-alone application)
2. reference: add RevitAPI.dll as a non-local reference of the project; also add System.Windows.Forms as a reference
3. class: change the class name so you will know what it is for later on, and inherit the IExternalCommand interface
4. method: write the code for the “execute” method, which is required by the inherited interface 
5. assembly: build your class to get the .dll file (the full address of this file will be needed in step 7)
6. link: set the start external progam property of your project to revit.exe (in the "debug" tab, or see the NOTE above for Express version users)
7. revit.ini: edit the [ExternalCommands] section in your revit.ini file (create a section with this name if there is no such section) to include the command name and tip that will be shown in Revit, as well as your .dll file information (not the VC# project file you actually coded) and the class name
done! set a breakpoint in your code and you can press F5 in VC# to run your program
 
An "Add-Ins" tab will be shown at the end of the Revit ribbon menu and your command is hidden beneath the "External Tools" button. here is a pic:

Reference:

Comments