hmm sorry. I'm too new at this to really understand your comment. I haven't had any problems createing the block itself. It seems to function as I want it to. These block attributes are not meant to be user edited. They are more meant to be a record of the calculations and settings that went into creating the block in the first place.
With regards to the drawOrder.MoveXXX() command, I moved it into what I bilevel is the correct space for it. The problem now is that idSendBack is null, even when the loop gets triggered. Even the object collection entityCopyCol, I created for the Cloned entities, is populated with 10 entries all of which are null.
This doesn't make sense to me, as the original object ID collection is populated properly.
Do the cloned objects keep the same object Id? That does not seem likely to me.
Thanks!
// put all drawn objects into a block.
Document doc1 = Application.DocumentManager.MdiActiveDocument;
Database db1 = doc1.Database;
using (Transaction trans3 = db1.TransactionManager.StartTransaction())
{
BlockTable blockTable = (BlockTable)trans3.GetObject(db1.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr3 = new BlockTableRecord();
btr3.Name = "UT_Check_1";
int i = 1;
while (blockTable.Has(btr3.Name))
{
i++;
btr3.Name = "UT_Check_" + i.ToString();
}
blockTable.UpgradeOpen();
blockTable.Add(btr3);
trans3.AddNewlyCreatedDBObject(btr3, true);
ObjectId idSendBack = ObjectId.Null;
ObjectIdCollection entityCopyCol = new ObjectIdCollection();
foreach (ObjectId objectId in ObjID)
{
Entity entity = (Entity)trans3.GetObject(objectId, OpenMode.ForRead);
Entity entityCopy = (Entity)entity.Clone();
entityCopyCol.Add(entityCopy.ObjectId);
if (entityCopy.GetType() == typeof(MText))
{
MText MtextSendBack = entityCopy as MText;
if (MtextSendBack.Contents.Contains("Status"))
{
doc.Editor.WriteMessage("\n You Entity Was Found!");
idSendBack = entityCopy.ObjectId;
}
}
btr3.AppendEntity(entityCopy);
trans3.AddNewlyCreatedDBObject(entityCopy, true);
}
DrawOrderTable drawOrder = trans3.GetObject(btr3.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;
if (idSendBack != ObjectId.Null)
{
drawOrder.MoveAbove(entityCopyCol, idSendBack);
}
Point3d origin = new Point3d(0, 0, 0);
BlockReference blockRef = new BlockReference(origin, btr3.ObjectId);
BlockTableRecord modelSpace = (BlockTableRecord)trans3.GetObject(db1.CurrentSpaceId, OpenMode.ForWrite);
modelSpace.AppendEntity(blockRef);
trans3.AddNewlyCreatedDBObject(blockRef, true);
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(typeof(UTOptions)))
{
AttributeDefinition attrDef = new AttributeDefinition();
attrDef.Position = new Point3d(0, 0, 0);
attrDef.Prompt = property.Name;
attrDef.Tag = property.Name;
attrDef.TextString = property.GetValue(utoptions)?.ToString() ?? "";
attrDef.Height = 2.5;
attrDef.Justify = AttachmentPoint.MiddleCenter;
attrDef.Visible = false;
//attrDef.Layer = utoptions.confltlyr;
AttributeReference attRef = new AttributeReference();
attRef.SetAttributeFromBlock(attrDef, blockRef.BlockTransform);
blockRef.AttributeCollection.AppendAttribute(attRef);
trans3.AddNewlyCreatedDBObject(attRef, true);
}
AttributeDefinition date = new AttributeDefinition();
date.Position = new Point3d(0, 0, 0);
date.Prompt = "Date Created";
date.Tag = "Date Created";
date.TextString = String.Format("{0}", DateTime.Now.ToString());
date.Height = 2.5;
date.Justify = AttachmentPoint.MiddleCenter;
date.Visible = false;
//date.Layer = utoptions.confltlyr;
AttributeReference dater = new AttributeReference();
dater.SetAttributeFromBlock(date, blockRef.BlockTransform);
blockRef.AttributeCollection.AppendAttribute(dater);
trans3.AddNewlyCreatedDBObject(dater, true);
trans3.Commit();
}