Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Attribute Values disappeared :(

3 REPLIES 3
Reply
Message 1 of 4
mehdi-guida
213 Views, 3 Replies

Attribute Values disappeared :(

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

3 REPLIES 3
Message 2 of 4
TerryDotson
in reply to: mehdi-guida

Message 3 of 4
mehdi-guida
in reply to: TerryDotson

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

 

Thank You

Message 4 of 4
TerryDotson
in reply to: mehdi-guida

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

Post to forums  

Rail Community


Autodesk Design & Make Report