Attribute Values disappeared :(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I used below codes to insert a blocks and fill out its attribute value.
The output should be 👇
but I got 👇
Would you please help me to solve this Issue?
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable BlkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord ms = (BlockTableRecord)tr.GetObject(BlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
if (BlkTbl.Has("bname"))
{
BlockTableRecord BlkRec = (BlockTableRecord)BlkTbl["bname"].GetObject(OpenMode.ForWrite);
BlockReference MyBlock = new BlockReference(ip, BlkRec.ObjectId);
MyBlock.Layer = "0";
if (MyBlock.AttributeCollection != null)
{
foreach (ObjectId item in MyBlock.AttributeCollection)
{
AttributeReference att = (AttributeReference)tr.GetObject(item, OpenMode.ForWrite);
if (att.Tag == "11")
{
att.TextString = "2";
}
}
}
ms.AppendEntity(MyBlock);
tr.AddNewlyCreatedDBObject(MyBlock, true);
}
else
{
ed.WriteMessage("\nBlock name [xx] is not found in current drawing.");
}
tr.Commit();
}