Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Using code I found in this forum, I wrote a small method for setting the value of a given attribute reference in a block reference:
public static void SetBlockAttributeValue(ObjectId objectId, string attributeTag, string attributeValue)
{
using (Transaction acTrans = application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{
try
{
BlockTable bt = (BlockTable)acTrans.GetObject(application.DocumentManager.MdiActiveDocument.Database.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)acTrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
BlockReference block = (BlockReference)acTrans.GetObject(objectId, OpenMode.ForWrite);
foreach (ObjectId attId in block.AttributeCollection)
{
AttributeReference attRef = (AttributeReference)acTrans.GetObject(attId, OpenMode.ForWrite);
if (attRef.Tag.ToUpper() == attributeTag.ToUpper())
{
attRef.TextString = attributeValue;
break;
}
}
acTrans.Commit();
}
catch (System.Exception ex)
{
application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nException reading '" + attributeTag + "' on entity " + objectId + ": " + ex.Message);
}
}
}
Through debugging, I can see that the attribute reference's TextString value is set correctly. Problem is the value is not recorded and the attribute reference value stays the same, as if the Commit() didn't happen. What am I doing wrong?
Solved! Go to Solution.