Its not so much the use of the transaction.AddNewlyCreatedObject method in the AddMissingAttribute routine, above, as its use when the attribute definitions are created in the first place:
private ObjectId CreateEasiBaseBlock(EasiBaseProperties easiBaseProperties)
{
ObjectId blockId = ObjectId.Null;
Document thisDrawing;
BlockTable blockTable;
Transaction transaction;
Circle innerCircle;
Circle outerCircle;
AttributeDefinition attribute;
try
{
thisDrawing = AutoCADUtility.GetDocument();
transaction = thisDrawing.Database.TransactionManager.TopTransaction;
blockTable = transaction.GetObject(thisDrawing.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
using (BlockTableRecord blockTableRecord = new BlockTableRecord())
{
blockTableRecord.Name = BlockNames.EasiBase;
// Insert the block near 0,0,0 but not on it
blockTableRecord.Origin = new Point3d(0, 1000, 0);
// Add inner circle to the block
innerCircle = new Circle();
innerCircle.Center = new Point3d(0, 1000, 0);
innerCircle.Radius = 600;
innerCircle.Layer = LayerNames.EasiBase;
innerCircle.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(innerCircle);
// Add inner circle to the block
outerCircle = new Circle();
outerCircle.Center = new Point3d(0, 1000, 0);
outerCircle.Radius = 650;
outerCircle.Layer = LayerNames.EasiBase;
outerCircle.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(outerCircle);
//Add the attributes
attribute = new AttributeDefinition(new Point3d(0, 1800, 0), "", EasiBaseBlockAttribute.SiteRef, EasiBaseBlockAttribute.SiteRef, ObjectId.Null);
attribute.Height = 80;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 1000, 0), "", EasiBaseBlockAttribute.EasiBaseSizeId, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 999, 0), "", EasiBaseBlockAttribute.CoverLevel, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 998, 0), "", EasiBaseBlockAttribute.InvertLevel, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 997, 0), "", EasiBaseBlockAttribute.OverallPREDLReference, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 996, 0), "", EasiBaseBlockAttribute.MouldTypeId, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 995, 0), "", EasiBaseBlockAttribute.SteelRingDepthId, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 994, 0), "", EasiBaseBlockAttribute.NumberOfSeatingRings, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 993, 0), "", EasiBaseBlockAttribute.CoverSlabDepthId, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 992, 0), "", EasiBaseBlockAttribute.NumberOf250Rings, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 991, 0), "", EasiBaseBlockAttribute.NumberOf500Rings, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 990, 0), "", EasiBaseBlockAttribute.NumberOf750Rings, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 989, 0), "", EasiBaseBlockAttribute.NumberOf1000Rings, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
attribute = new AttributeDefinition(new Point3d(100, 990, 0), "", EasiBaseBlockAttribute.EasiBaseId, "", ObjectId.Null);
attribute.Height = 0.5;
attribute.Visible = true;
attribute.Layer = LayerNames.EasiBase;
attribute.ColorIndex = 256; //Color by layer
blockTableRecord.AppendEntity(attribute);
//Add the block to the record
blockTable.UpgradeOpen();
blockTable.Add(blockTableRecord);
transaction.AddNewlyCreatedDBObject(blockTableRecord, true);
blockId = blockTableRecord.Id;
}
}
catch (Exception ex)
{
MessageBox.Show("EasiBase.CreateEasiBaseBlock : " + ex.Message, MessageHeadings.ExceptionError);
}
return blockId;
}
I would expect to see each artefact in the block to be added to the transaction separately. Its not a problem. I just like to understand the reasoning for it...well, within reason (it's not like I'm doing this for fun).