Vous êtes sur la page 1sur 1

DE205-4: AutoCAD® .

NET Basics

Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Hello
World from VB.NET!")

There are several other Autodesk.AutoCAD namespaces, but these are the three you’ll need in
just about every AutoCAD add-in you write. (In this example, DatabaseServices is not strictly
necessary).

<CommandMethod("HelloWorld")> is an attribute. This is telling AutoCAD to run the


subroutine MyMethod when the user types HELLOWORLD on the command line. The rest of
the code should be self-explanatory.

That’s all the code we need. But before we can test our first AutoCAD add-in we have to set one
more project setting. Double-click again on My Project in the Solution Explorer; select the
Debug tab; set the Start Action to Start external program; and enter the location of the AutoCAD
executable – the default location is C:\Program Files\AutoCAD 2009\acad.exe. This is telling
Visual Studio that you’re going to load your DLL into the AutoCAD process space to debug it5.

Now we’re ready to run our add-in. Hit F5 to start debugging, and AutoCAD will launch. Type
NETLOAD on the command line and hit ENTER. In the NETLOAD file select dialog, navigate to
the location of your compiled .NET assembly DLL. This should be in this location, unless you
changed your default project settings:

5
The AutoCAD .NET API can only be used from inside the AutoCAD process space. You can’t use
admgd.dll and acdbmgd.dll in a standalone executable. (But see the section on RealDWG at the end of
this document).

Vous aimerez peut-être aussi