Getting Started with .NET

ActiveDwg .Net Page  
This article reviews using the .Net programming environment in your work.
Copyright©2000-2009 ActiveDwg.com

Beginning with AutoCAD 2010, VBA is no longer included in the base AutoCAD installation. If you wish to continue using it for 2010 you will need to download and install the VBA Enabler package (here). We expect that AutoCAD will not even support VBA in the near future. Although it would be easy to blame Autodesk, it is in fact simply a result of their reliance on Microsoft for the technology, and Microsoft stopped developing and issuing new VBA licenses several years ago in the move toward toward 64-bit platforms. Progress...

One thing we particularly liked about VBA was that the same module could be used across many AutoCAD releases. Most would work without any change from the current version all the way back to Release 2000; the exceptions, of course, being those that were written to make use of features of newer releases. The .Net assemblies, like ObjectARX programs, will need to be recompiled each time AutoCAD is no longer binary compatible with the prior version or versions. Recently, this has been every 3 releases or so. We have 60-70 VBA modules that have worked for a long time and now, if we continue with new AutoCAD releases, we will need to, at the very least, recompile them to continue using them. This will be tedious at best.

It is well known that AutoCAD provides many different ways to customize your work space through its various API's (Application Programming Interfaces). There is bound to be at least one that will suit your needs and abilities. Up till now, our favorite flavor has been VBA (Visual Basic for Applications), but with its imminent demise it is time to look at another method for bending AutoCAD to do our bidding. The .Net environment is language nuetral in that you can use any of several programming languages to create your assemblies and, depending on your perspective, there are good arguments for using any of them. We will be using using C# (C-sharp) and VB.Net.
Through .Net AutoCAD has made most of its core functions more readily available through managed wrappers for ObjectARX.

To get started using the AutoCAD .Net API, you will need to make a few preparations:
1) Obtain and install the Microsoft .Net Framework. Which version you need depends upon the AutoCAD version you are running. Generally you will want the latest version (2010 installs version 3.5),
2) You can use any of several programming languages to access AutoCAD's .Net API, and we will use C# and VB.Net. While all you absolutely need to develop and compile code is a text editor and the .Net Framework (using its command line compiler), we suggest you latch onto a dedicated C# IDE to take advantage of its keyword coding, intellisense, etc. We will be using #develop (Sharp Develop), an OpenSource IDE. The version you get will depend upon your version of the .Net Framwork that is available on your machine. We will be using version 3.0. As noted, this is not the only way to create your .Net assemblies; if you have Microsoft Visual Studio installed, the ObjectARX package comes with a set up wizard to help get the basic assemblies set up; you can also grab the Visual C# (or VB.Net) Express Edition for Microsoft, etc. You can also get by with a text editor and the command line compilers provided with the .Net Framework - but we suggest you use a programmer's editor,
3) We presume you have downloaded, installed, studied, and worked through the Autodesk Labs .Net examples. If not, you should do so. They are available at the Autodesk Developer Center,
4) The managed wrapper classes are documented as part of the ObjectARX package, so you should download, install, and review this material as well. We are using ObjectARX 2010. In addition to the documentation, this package also includes C# and VB.Net samples under 'ObjectARX 2010\Samples\dotNet'.

There are a couple preliminaries to touch on after you get the .Net Framework, Sharp-Develop, and ObjectARX set up on your system:
1) In AutoCAD: add a new button to a convenient toolbar or ribbon panel, or add a command alias, to run the 'NETLOAD' command. You will be using this to load your .Net assemblies in AutoCAD,
2) In SharpDevelop: go to 'Tools > Options > Tools > Help 2.0 Environment' and change the 'Help Collection' to point to your .Net documentation.

This should get you started. Next we will start coding...


Home | AutoCAD | Downloads | Help | Sites | VBA
(c)2000-2010 - ActiveDwg.com - Aiding and Abetting CAD Productivity