I want to ask a questions about csharp and autocad interaction. Could I manage the autocad using by csharp codes, I mean, I should create a program with C#, and when I press a button, I should draw a line in autocad. is it possible?
I found a page about this subject
at the above webpage, is proper documentation?
Thank you for your response,
But when I try code that you advice, It didnt run, it gave a failure as below
Could not load file or assembly 'accoremgd,
Could you send a simple and basic project about this subject,
Full test code
public partial class Form1 : Form
private void Form1_Load(object sender, EventArgs e)
public static void AddLine()
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.D
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
//open block table for read
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
// opren the block table record model space for write
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelS
// create line that starts at 5,5 ends at 12,3
Line acLine = new Line(new Point3d(5, 5, 0), new Point3d(12, 3, 0));
// add the new object to the block table record and the transaction
//save the new object to the database
private void button1_Click(object sender, EventArgs e)
You have to add the references to the AutoCAD .NET API libraries to your project (see here).
These DLLs are mosty: AcDbMgd.dll and AcMgd.dll plus, if you're targeting A2013 or 2014, AcCoreMgd.dll.
The code posted by mzakiralam defines an AutoCAD command. It have to be compiled as class library (dll) and loaded into AutoCAD with the NETLOAD command.
The AutoCAD .NET API is designed to run in-process only, if you want to make an out-of-process stand-alone application (exe), you'll have to get or create an instance of AutoCAD and use the AutoCAD ActiveX Automation (COM) libraries.
You should have a look here.
I canl send you complete example project in VB if you still required. In the mean time you should have look on basics of AutoCAD.NET API (use below link please for that). How to create a project and how to load that assembly into AutoCAD. Please remember that as _gile mentioned in his previous message of this thread that you have to add proper reference to build DLL.
I attached a little VS2010 solution which contains 3 projects to show you different ways to make a stand-alone application to interact with AutoCAD. All uses the AutoCAD COM API.
- InteropSample uses references to Autodesk.AutoCAD.Interop and Autodesk.AutoCAD.Interop.Common which are version and plateform dependant, so you may have to change them.
- DynamicSample uses the dynamic type to avoid having AutoCAD.Interop references. It requires the .NET Framework 4.
- LateBindingSample uses late binding and reflectionto avoid having AutoCAD.Interop references. It contains some extension methods to make the code more readable.
Thanks to everbody to your help,
I applied wrong method to create line via exe file,
Thank you for your basic project it is important example for me, I think it is solve my problem.
Access a broad range of knowledge to help get the most out of your products and services.