Welcome back! This month we're going to create the same two simple AutoCAD commands that we did last month, but this time in C# (pronounced C-sharp). As we go through this process, you may want to reference last month's column. As with last month's code, you can use any editor to create these commands -- including Windows' NotePad -- because no graphics are involved. I will use Microsoft's Visual Studio this month since I used SharpDevelop last month. This way you can compare the screen shots to see how similar both editors are. For this article, we are going to recreate the classic "Hello World" example and throw the text into AutoCAD's command line and into an MText object just like last month. The code is derived from the Autodesk sample available within the AutoCAD 2006 install, AutoCAD 2006 ObjectARX toolkit and from the Autodesk website. The twist this month is we will use C# instead of VB.NET.
To begin, I will open Microsoft Visual Studio 2003. You can use Microsoft Visual Studio 2002, 2005 or the free beta Microsoft Visual Express C# 2005. All offer a very similar interface. At the start page, I will select Visual C# Projects and a Class Library (figure 1).Next I will add the references to our project just like with Visual Basic 6, VBA or last month's VB.NET project. As was the case last month, you will need to browse to AutoCAD's installed directory and select the managed libraries: ACDBMGD.DLL and ACMGD.DLL (figures 2 and 3). You do not select the AutoCAD 2006 type library in the COM tab! That would create a COM InterOp project similar to VB6-based programming. This project is going to be a .NET managed project, so you need to hook into the MGD files.
|