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();
}
... need more details.
Then click the bold link in my post and review the Autodesk blog supplied example.
Questions like this one regarding plain AutoCAD functionality may get faster responses if posted in the AutoCAD .NET forum. If code refers to Civil3D objects, this is the best place.
Can't find what you're looking for? Ask the community or share your knowledge.