Тема: Обновить значения атрибутов в блоке
Здравствуйте!
Пишу на C# для Autocad 2005.
Каким способом можно программно редактировать значения текстовых аттрибутов блока.
Свой вариант кода привожу ниже:
Database _db2 = HostApplicationServices.WorkingDatabase; Autodesk.AutoCAD.DatabaseServices.TransactionManager tm2 = _db2.TransactionManager; Transaction tr2 = tm2.StartTransaction(); BlockTable bt = (BlockTable)tr2.GetObject(_db2.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr2.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead); foreach (ObjectId obId in btr) { DBObject dbObj = tr2.GetObject(obId, OpenMode.ForRead); BlockReference blkRef = dbObj as BlockReference; if (blkRef!=null) { BlockTableRecord blkDef = (BlockTableRecord)tr2.GetObject(blkRef.BlockTableRecord,OpenMode.ForRead); WinForms.MessageBox.Show("\nGot a block named " + blkDef.Name); foreach (ObjectId idAtt in blkDef) { Entity ent = (Entity)tr2.GetObject(idAtt, OpenMode.ForNotify); if (ent is AttributeDefinition) { AttributeDefinition attDef = (AttributeDefinition)ent; AttributeReference attRef = new AttributeReference(); attRef.SetAttributeFromBlock(attDef, blkRef.BlockTransform); attRef.SetPropertiesFrom(attDef); WinForms.MessageBox.Show(attRef.Tag); if (attDef.Tag == "FILE") { attRef.TextString = this.cadApp.ActiveDocument.FullName; } } } } } tr2.Commit();