easiBaseOutline = Utility.AddCircleToDrawing(insertPoint, 600, LayerNames.TemporaryEntity);
//Ask for the output pipe
outputPipe = GetOutputPipe();
if (outputPipe == null)
{
//ESC pressed, so stop the command
return;
}
//Check that the outlet pipe intersects with the EasiBase outline
//Ask for the inlet pipes
//Open the EasiBase form
}
catch (Exception ex)
{
MessageBox.Show("EasiBase.Create" + ex.Message, MessageHeadings.ExceptionError);
}
finally
{
if (easiBaseOutline != null)
{
easiBaseOutline.Erase();
}
}
public static Circle AddCircleToDrawing(Point3d InsertPoint, double Radius, string LayerName)
{
Document thisDrawing;
Circle newCircle = null;
BlockTable blockTable;
BlockTableRecord blockTableRecord;
try
{
thisDrawing = GetDocument();
if (thisDrawing == null)
{
return newCircle;
}
// Start a transaction
using (Transaction autoCADTransaction = thisDrawing.Database.TransactionManager.StartTransaction())
{
// Open the Block table for read
blockTable = autoCADTransaction.GetObject(thisDrawing.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
blockTableRecord = autoCADTransaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
using (newCircle = new Circle())
{
// Create the circle entity
newCircle.Center = InsertPoint;
newCircle.Radius = Radius;
newCircle.Layer = LayerName;
newCircle.Visible = true;
// Add the new object to the block table record and the transaction
blockTableRecord.AppendEntity(newCircle);
autoCADTransaction.AddNewlyCreatedDBObject(newCircle, true);
}
// Save the new object to the database
autoCADTransaction.Commit();
}
}
catch (Exception ex)
{
MessageBox.Show("Utility.AddCircleToDrawing" + ex.Message, MessageHeadings.ExceptionError);
}
return newCircle;
}
public void Erase(ObjectId id)
{
if (id.Database.TransactionManager.TopTransaction != null)
id.GetObject(OpenMode.ForWrite).Erase();
else
#pragma warning disable CS0618
using (var obj = id.Open(OpenMode.ForWrite))
obj.Erase();
#pragma warning restore CS0618
}
And it gets worse. This ObjectId class is non nullable, so I can't set a default value to return.ObjectId has a Null static property and a IsNull instance property.
But I can work with these ObjectId objects. I'm not working with one big fat transaction if I can possibly avoid it...above all else I want readability (encapsulation) and want to avoid passing parameters around like sweeties at a kids party.Using the top transaction allows you to work with DBObjects instead of ObjectId and passing the transaction to the called method is not mandatory.
I like to use Extension methods called from within the top transaction, here's a little example...