This is in response to a PM.
Please note that I will usually ignore personal requests, but in this case I had something handy, so ...
The process of adding entities to a drawing Database is/canbe broken into 6 basic stages.
//
//Start a database transaction
//
//Create object
//
//Open modelspace for writing
//
//Add the object to modelspace
//
//Inform the transaction of the new object
//
//Commit the transaction
and here's some sample code.
There are several ways to achieve this, with helpers etc, but the process will always break down to the 6 steps
Any Comments ? ?
[CommandMethod("CX1", CommandFlags.Modal)]
public static void CircleX1()
{
Database db = AcadApp.DocumentManager.MdiActiveDocument.Database;
//
// Confirm the layer exists
ObjectId layerId = LibTools.CreateLayer("LayerCX1", 113, "CONTINUOUS");
//
// This point is in World UCS, irrespective of UCS
// Look at Matrix translations
Point3d centerPoint = new Point3d(20.0, 20.0, 0.0);
Vector3d normalZ = new Vector3d(0.0, 0.0, 1.0);
double radius = 50.20;
//
//Start a database transaction
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//
//Create object
Circle squircle = new Circle(centerPoint, normalZ, radius);
squircle.Layer = "LayerCX1";
//
//Open modelspace for writing
BlockTableRecord modelSpace = (BlockTableRecord)tr.GetObject(GetActiveModelSpaceId(db), OpenMode.ForWrite);
//
//Add the object to modelspace
modelSpace.AppendEntity(squircle);
//
//Inform the transaction of the new object
// tr.TransactionManager.AddNewlyCreatedDBObject(squircle, true); // rev kwb1217
tr.AddNewlyCreatedDBObject(squircle, true);
//
//Commit the transaction
tr.Commit();
}
}
public static ObjectId GetActiveModelSpaceId(Database db)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
return (ObjectId)bt[BlockTableRecord.ModelSpace];
}
}
// rev kwb1217