public void UpdateTitleBlock() { Database db = HostApplicationServices.WorkingDatabase; Transaction trans; BlockTableRecord btr; BlockTable bt; BlockReference br; BlockTableRecord blkObj; Entity ent; //Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; using (Transaction trans = db.TransactionManager.StartTransaction()) { try { BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForRead); foreach (ObjectId bId in btr) { using (Entity ent = (Entity)trans.GetObject(bId, OpenMode.ForRead, false)) { if (ent.GetRXClass().Name.ToString() == "AcDbBlockReference") { BlockReference br = (BlockReference)ent; BlockTableRecord blkObj = (BlockTableRecord)trans.GetObject(br.BlockTableRecord, OpenMode.ForRead); if ((blkObj.HasAttributeDefinitions) && (blkObj.Name == "TITLEBLK")) { Autodesk.AutoCAD.DatabaseServices.AttributeCollection attcol = br.AttributeCollection; foreach (ObjectId attId in attcol) { AttributeReference attRef = (AttributeReference)trans.GetObject(attId, OpenMode.ForWrite); switch (attRef.Tag) { case "DWG_NO.": attRef.TextString = "My Number"; break; case "SHEET_NUMBER": attRef.TextString = "My Sheet"; break; case "REVISION_NUMBER": attRef.TextString = "My Rev"; break; } string str = ("\n Updated Attribute Tag: " + attRef.Tag + " Attribute String: " + attRef.TextString + "\n"); } } } } } trans.Commit(); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); MessageBox.Show("Unexpected Error: " + ex.ToString()); } } } private void somefunction() { Database db = AcadApp.DocumentManager.MdiActiveDocument.WorkingDatabase; Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; using (Transaction trans = db.TransactionManager.StartTransaction()) { try { BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForRead); foreach (ObjectId bId in btr) { using (Entity ent = (Entity)trans.GetObject(bId, OpenMode.ForRead, false)) { if (ent.GetRXClass().Name.ToString() == "AcDbBlockReference") { BlockReference br = (BlockReference)ent; BlockTableRecord blkObj = (BlockTableRecord)trans.GetObject(br.BlockTableRecord, OpenMode.ForRead); if ((blkObj.HasAttributeDefinitions) && (blkObj.Name == "TITLEBLK")) { Autodesk.AutoCAD.DatabaseServices.AttributeCollection attcol = br.AttributeCollection; foreach (ObjectId attId in attcol) { AttributeReference attRef = (AttributeReference)trans.GetObject(attId, OpenMode.ForWrite); switch (attRef.Tag) { case "DWG_NO.": attRef.TextString = "My Number"; break; case "SHEET_NUMBER": attRef.TextString = "My Sheet"; break; case "REVISION_NUMBER": attRef.TextString = "My Rev"; break; } string str = ("\n Updated Attribute Tag: " + attRef.Tag + " Attribute String: " + attRef.TextString + "\n"); ed.WriteMessage(str); } } } } } trans.Commit(); } catch (System.Exception ex) { ed.WriteMessage("Unexpected Error: " + ex.ToString()); } } }