Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Attribute Values disappeared :(

mehdi-guida
Advocate

Attribute Values disappeared :(

mehdi-guida
Advocate
Advocate

Hi,

I used below codes to insert a blocks and fill out its attribute value.

The output should be 👇

mehdiguida_1-1686855094351.png

but I got 👇

mehdiguida_0-1686854824879.png

 

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();
}

0 Likes
Reply
260 Views
3 Replies
Replies (3)

TerryDotson
Mentor
Mentor
0 Likes

mehdi-guida
Advocate
Advocate

Thank you for reply, but i am beginner and need more details.

 

Thank You

0 Likes

TerryDotson
Mentor
Mentor

... 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.

0 Likes