tu peux utilisé les cette commande
AcadApplication app = new AcadApplication();
AcadDocument doc1 = app.ActiveDocument;
for exemple: to create a line
using System;
using Autodesk.AutoCAD.Runtime;
using System.Collections.Generic;
using System.Windows.Forms;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
[CommandMethod("line")]
public void line() // This method can have any name
{
AcadApplication app = new AcadApplication();
AcadDocument doc1 = app.ActiveDocument;
//This example adds a line in model space
AcadLine lineObj;
double[] startPoint = new double[3];
double[] endPoint = new double[3];
//Define the start and end points for the line
startPoint[0] = 1; startPoint[1] = 1; startPoint[2] = 0;
endPoint[0] = 50; endPoint[1] = 200; endPoint[2] = 0;
//Create the line in model space
lineObj = doc1.ModelSpace.AddLine(startPoint, endPoint);
app.Application.Visible = true;
doc1.Regen(AcRegenType.acAllViewports);
app.ZoomAll();
}
ou bien vous pouvez appeler la DLL dans autocad en utilisant la commande "netload"
voici un autre exemple:
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using System;
using Autodesk.AutoCAD.Interop.Common;
namespace Linetype
{
public class Commands
{
[CommandMethod("line")]
public void CreateComplexLinetype()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Transaction tr2 = db.TransactionManager.StartTransaction();
using (tr2)
{
BlockTable bt = (BlockTable)tr2.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr2.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
PromptPointOptions opts = new PromptPointOptions("\nEnter start Point:");
PromptPointResult res = ed.GetPoint(opts);
PromptPointOptions opts2 = new PromptPointOptions("\nEnter end Point:");
PromptPointResult res2 = ed.GetPoint(opts2);
Line ln = new Line(res.Value, res2.Value);
ln.SetDatabaseDefaults(db);
Color currentcolor = new Color();
ln.Color = Color.FromRgb(0, 255, 0);
btr.AppendEntity(ln);
tr2.AddNewlyCreatedDBObject(ln, true);
tr2.Commit();
}
}
}
}
suivez les étapes suivantes:
1-creer un nouveau projet en visuel studio-->new-->project-->visuel c#-->AutoCAD Managed C# Project,
2-copier le code source,
3-compiler l'application (build or F7)
4-lancer autocad
5-exécuter la commande "netload"
6-charger votre dl dans autocad
7-tester votre commande "line" (créer par la dll )dans autocad tj.
j'espère que ça va marcher ,
bon courage.