Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a block in the drawing which contains an attribute whoes tag is "24GENPOS", What I want to do is to change the layer and color of that specific attribute definition, I am starting with the color first, The program can correctly locate the block and execute the code, however the color is not changed.
public void cmdATTLAY() { var attName = "24GENPOS"; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Database db = HostApplicationServices.WorkingDatabase; ObjectId blkTabId = db.BlockTableId; using (Transaction trans = db.TransactionManager.StartTransaction()) { try { BlockTable blkTab = trans.GetObject(blkTabId, OpenMode.ForRead) as BlockTable; foreach(ObjectId blkTabRecId in blkTab) { bgFunction.ChangeAttLayer(blkTabRecId, attName, "something"); } } catch(Autodesk.AutoCAD.Runtime.Exception ex) { ed.WriteMessage("Error : " + ex.Message); } } }
public static void ChangeAttLayer(ObjectId blockId,string attName, string layerName) { using (Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()) { BlockTableRecord blkTabRec = trans.GetObject(blockId, OpenMode.ForRead) as BlockTableRecord; foreach (ObjectId objId in blkTabRec) { DBObject objDb = trans.GetObject(objId, OpenMode.ForWrite); if (objDb is AttributeDefinition) { var attDef = (AttributeDefinition)objDb; if (attDef.Tag == attName) { attDef.ColorIndex = 1; } } } trans.Commit(); } }
Solved! Go to Solution.