Академический Документы
Профессиональный Документы
Культура Документы
Introduction
This document provides a step-by-step tutorial on how to create, load and debug a simple VB .NET application for AutoCAD using the Visual Studio Express development environment. The document focuses on setting up and using the Visual Studio Express environment. We do not elaborate on the AutoCAD .NET API
itself. There are resources noted at the end of this tutorial to help with learning the AutoCAD .NET API.
3) Select the Class Library Template (shown above) and enter a suitable name in the Name: text
field. Here, we chose MyVBAcadApp.
4) A new Project is created and the Visual Studio Express window should look something like this:
1) In your Visual Studio 2012 Express window you should see the Solution Explorer tab on the right. If
you dont see it, click the ViewSolution Explorer menu item or type Ctrl+W+S.
2) Go to the Solution Explorer tab on the right side of the Visual Studio 2010 Express window select
the Show All Files button as shown below.
3) Select the project folder MyVBAcadApp, right click and select properties.
4) In the application tab Ensure that .NET Framework 4.5 is the target framework.
US/CANADA
800-356-9050
Page 2 Using Visual Studio Express 2012 to Create an AutoCAD and Civil 3D 2015 .NET Add-in
imaginit.com
5) Select the Compile tab and in the Target CPU select x64 to compile to 64bit
1.2
1) Go to the Solution Explorer tab on the right side of the Visual Studio 2012 Express window select
the Show All Files button as shown below.
2) The above step will display the References folder in the Solution Explorer as shown below.
3) Right-click on the References folder and select Add Reference item in the resulting context
Reference Manager menu.
4) Click on the Browse button and Navigate to the location of the AutoCAD-specific Reference files.
Note: You will find AutoCAD-specific reference files in a couple of locations. If you have ObjectARX
SDK installed, you can navigate to the Include folder (I would navigate to C:\ObjectARX\2012\inc-
win32 for 32 bit platforms and C:\ObjectARX\2012\inc-x64 for 64 bit) for the references. In the snap
shot above, we navigated to the inc-win32 folder.
US/CANADA
800-356-9050
Page 3 Using Visual Studio Express 2012 to Create an AutoCAD and Civil 3D 2015 .NET Add-in
imaginit.com
Alternatively, you can navigate to the AutoCAD or Civil 3D Install Folder and find the references
there as shown below:
5) Select the DLL files acmgd.dll, acdbmgd.dll and AcCoreMgd.dll from the location you browse to
and click the ADD button. These files contain all the necessary .NET APIs to create a generic Auto
CAD .NET application
You can also type *mgd.dll to filter for the required assemblies.
US/CANADA
800-356-9050
Page 4 Using Visual Studio Express 2012 to Create an AutoCAD and Civil 3D 2015 .NET Add-in
imaginit.com
Select the DLL files acmgd.dll, acdbmgd.dll, AcCoreMgd.dll and AecBaseMdg.dll, AecDBMgd.
dll from the location you browse to and click the OK button. These files contain all the necessary
.NET APIs to create a generic AutoCAD .NET application.
Note: You can select multiple files (two files in this case) by pressing the Ctrl key while selecting
them with the mouse.
7) Now that we have the classes referenced we can import them. Add the necessary Namespaces to
the source files for convenient access to the AutoCAD .NET APIs. Here are the most commonly used
AutoCAD .NET API specific namespaces:
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
You can add these namespaces at the top of the Class1.vb source file as shown below.
Note: We will not be elaborating on the purposes of the namespaces and the AutoCAD .NET APIs in
this tutorial. You can find a lot more information on this in the references provided at the end of this
tutorial.
1.3
Creating a Command
Add the command method that implements the command(s) you need. Here is an example of a command method implementing the command we use:
Define command MyVBCommand
<CommandMethod(MyVBCommand)> _
Public Sub Cmd1() This method can have any name
Type your code here
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage(My First command implemented in VB .NET Express Edition)
End Sub
Note: We will not be elaborating on the creation of commands and the AutoCAD .NET APIs in this
tutorial. You can find a lot more information on this in the references provided at the end of this tutorial.
US/CANADA
800-356-9050
Page 5 Using Visual Studio Express 2012 to Create an AutoCAD and Civil 3D 2015 .NET Add-in
imaginit.com
1.4
You can save the project by clicking the FileSave All menu item or using Ctrl+Shift+S.
1.5
The last step is to Build the application. Use the BuildBuild menu item to build your application.
You now have a functional AutoCAD VB .NET Application!
1.6
You can load your compiled application into AutoCAD now using the NETLOAD command and run the
application by typing myVBCommand at the command prompt, however, before we can truly debug our
application we have to edit our ApplicationName.vbproj.user file so that Visual Studio Express 2012 can
play nice with AutoCAD.
1.7
The Visual Studio 2012 Express Edition does not provide any method through its user interface to specify
a debug application path to launch AutoCAD from the Visual Studio 2012 Express Edition environment.
So we have to play a small trick here:
1) Save the project and close Visual Studio 2012 Express Edition.
2) Navigate to the location of the project in Windows Explorer. My Project is in the folder
C:\My Documents\Visual Studio 2012\Projects\MyVBAcadApp\MyVBAcadApp.
US/CANADA
800-356-9050
Page 6 Using Visual Studio Express 2012 to Create an AutoCAD and Civil 3D 2015 .NET Add-in
imaginit.com
3) Open the Project file <ApplicationName.vbproj.user> in a text editor. I used Notepad as the
text editor and my application project file is named MyVBAcadApp.vbproj.user. You will notice that
it is an XML file. Add the following two XML Nodes:
<PropertyGroup Condition=$(Configuration)|$(Platform) == Debug|AnyCPU>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files\Autodesk\AutoCAD 2015\acad.exe</StartProgram>
</PropertyGroup>
Note: The StartProgram node stores the path of the AutoCAD application acad.exe. You will
have to modify this path to the correct path to the acad.exe executable on your machine.
1.8
Finally we are done all our setup for creating our VB project as well as setting up you VBE debugger.
1) Select the StartDebug Menu item or press F5. This will launch the AutoCAD application from the
Visual Studio 2012 Express Edition debugging environment.
US/CANADA
800-356-9050
Page 7 Using Visual Studio Express 2012 to Create an AutoCAD and Civil 3D 2015 .NET Add-in
imaginit.com
2) Once AutoCAD is launched, run the NETLOAD command. This will display the Choose .NET
Assembly dialog (as shown below):
1.9
1) In VS2012 Set the cursor at the line of code to which you want to break.
2) Click the DebugToggle Breakpoint menu item or press the F9 key. Here is a snapshot of the
break point at the point of code where we set the Editor object (The Red dot indicates the break point):
US/CANADA
800-356-9050
Page 8 Using Visual Studio Express 2012 to Create an AutoCAD and Civil 3D 2015 .NET Add-in
imaginit.com
3) In AutoCAD, run the command (in our case MyVBCommand) on the AutoCAD command line and
you will see the break point hit:
You can now use the debugger keys like F8 or Shift+F8 etc. to traverse through the code.
Congratulations, you have successfully used Visual Studio 2012 Express Edition to create and use a
.NET application in AutoCAD!
1) We need to add C3D references, in the solution explorer Right-click on the References folder
and select Add Reference
2) Browse to the Civil 3D Install Folder (the default location is C:\Program Files\Autodesk\AutoCAD
2015\ACA) and select and add the AecBaseMgd.dll.
3) Next we need to add the C3D references, browse to the Civil 3D Install Folder (the default location is
C:\Program Files\Autodesk\AutoCAD 2015\C3D) and select and add the AecDbMgd.dll.
4) Once these references have been added, ensure you change the properties to set Copy Local to
False.
5) Add the necessary Namespaces to the source files for convenient access to the Civil 3D .NET APIs.
Imports Autodesk.Civil.ApplicationServices
Imports Autodesk.Civil.DatabaseServices.Styles
6) Add the command method that implements the command(s) you need.
a. Here is an example of the command method implementing the command we use: I received the
following from my buddy Partha at Autodesk (although I have not had the pleasure of having a beer
with Partha I will consider him a friend, for all the help I got from him).
US/CANADA
800-356-9050
Page 9 Using Visual Studio Express 2012 to Create an AutoCAD and Civil 3D 2015 .NET Add-in
imaginit.com
<CommandMethod(StylesAlignmentInfo)> _
Public Sub GetTheAlignmentStyles()
Note: We will not be elaborating on the creation of commands and the AutoCAD .NET APIs in this
tutorial. You can find a lot more information on this in the references at the end of this tutorial.
US/CANADA
800-356-9050
Page 10 Using Visual Studio Express 2012 to Create an AutoCAD and Civil 3D 2015 .NET Add-in
imaginit.com
7) Now that your Civil 3D application is created, as in the AutoCAD steps above you can proceed to:
d. And finally run the app by typing StylesAlignmentInfo at the command prompt.
8) The app will display all the alignment styles in your current drawing.
Debug AutoLoad .dll with Script file (addendum by Justin Ralston 06-12-2010 02:08 AM)
To speed up the debug process create a .scr script file with the following contains to do the netload and
open your test drawing.
US/CANADA
800-356-9050
Page 11 Using Visual Studio Express 2012 to Create an AutoCAD and Civil 3D 2015 .NET Add-in
imaginit.com
Once you have created the script file add the command line arguments to VB.net Express at the following
location.
References:
1)
US/CANADA
800-356-9050
Page 12 Using Visual Studio Express 2012 to Create an AutoCAD and Civil 3D 2015 .NET Add-in
imaginit.com