Developing AutoCAD addin/plugin using C#

24 Jan

  • In Visual Studio .NET, create a class library solution and project.


  • Add Reference from the Project menu or Solution Explorer, browse to the \inc or \incx64 directory of the ObjectARX SDK and select acdbmgd.dll and acmgd.dll.
  • Create a new class or rename the auto-created class


  • In the main class file, add the namespaces you will use.

    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.Runtime;

  • Add a C# function


Note the attributes are important and must be used, otherwise the command will not be fired.

  • In AutoCAD command prompt, type “netload”, then browse to the C# Library assembly, and click OK.
  • In AutoCAD command prompt, type the function name, in our case, it is  “CreateIt”



Now add some more meaningful code:

public static void CreatePorousObject() 
      Point3d center=new Point3d(9.0, 3.0, 0.0);
      Vector3d normal=new Vector3d(0.0, 0.0, 1.0);
      Circle pCirc = new Circle(center, normal, 2.0);

      Database acadDB = HostApplicationServices.WorkingDatabase;
      Autodesk.AutoCAD.DatabaseServices.TransactionManager acadTransMgr =acadDB.TransactionManager;
      Transaction acadTrans = acadTransMgr.StartTransaction();
      BlockTableRecord acadBTR = (BlockTableRecord)acadTrans.GetObject(acadDB.CurrentSpaceId,OpenMode.ForWrite);
      acadTrans.AddNewlyCreatedDBObject(pCirc, true);
Now re-compile and run, you will see a circle drawn in AutoCAD. 

Posted by on January 24, 2010 in CAD, Dotnet/C#


4 responses to “Developing AutoCAD addin/plugin using C#

  1. Eike

    April 25, 2013 at 5:34 pm

    Hi! I have tried your quick Plugin Tutorial.
    However I get an errormessage, when I try to debug:

    Here are my questions:

    – I am using AutoCAD Architecture 2011and Visual Studio C# 2012 Express.
    Are there any compatibility problems?

    – I downloaded ObjectARX 2011 onto my C drive and am referencing to the .dll in here:
    C:\ObjectARX 2011\inc
    This should all be fine? Am I using a wrong version?

    – When I debugg it tells me that a class library cannot be started directly and that i should add a new project to the project folder and start from here, referencing the class library.
    However, when I do that i get an error again..and so on.

    I’d be really happy for any comment.


  2. Dileep

    July 16, 2013 at 5:19 pm

    Autocad managed assemblies are not going to work.
    You need to use the Type Library Instead.

  3. xinyustudio

    July 16, 2013 at 5:23 pm

    Can you offer some links regarding to aforementioned changes? Thanks.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: