Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
// Create an in memory circle
using (Circle acCirc = new Circle())
{
acCirc.Center = new Point3d(2, 2, 0);
acCirc.Radius = 5;
// Adds the circle to an object array
DBObjectCollection acDBObjColl = new DBObjectCollection();
acDBObjColl.Add(acCirc);
// Calculate the regions based on each closed loop
DBObjectCollection myRegionColl = new DBObjectCollection();
myRegionColl = Region.CreateFromCurves(acDBObjColl);
Region acRegion = myRegionColl[0] as Region;
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acRegion);
acTrans.AddNewlyCreatedDBObject(acRegion, true);
// Dispose of the in memory circle not appended to the database
}
// Save the new object to the database
acTrans.Commit();
}
// convertToBlock(createPolyline(new Point2d(0, 0), Width, Height));