Skip to content

Instantly share code, notes, and snippets.

Last active August 16, 2022 00:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
[assembly: CommandClass(typeof(MyFirstCadPlugin.Class1))]
namespace MyFirstCadPlugin
public class Class1
public void HelloCommand()
// Here we connect to the active AutoCAD Document and Database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Here we create a Transaction in the current Database
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
// Access to the Model Blocktable for write
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForWrite) as BlockTable;
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
// Create a Circle with its center in the coordinates origin and radius = 50.
Circle myCircle = new Circle();
myCircle.Center = new Point3d(0, 0, 0);
myCircle.Radius = 50;
// Create text with "Hello!" in the middle of the circle
DBText myText = new DBText();
myText.Height = 20;
myText.TextString = "Hello!";
myText.Justify = AttachmentPoint.MiddleCenter;
// Append Circle and Text to the Blocktable record and Database
acTrans.AddNewlyCreatedDBObject(myCircle, true);
acTrans.AddNewlyCreatedDBObject(myText, true);
// Finish Transaction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment