Тема: При вставке блока теряются атрибуты
Привет, коллеги! Помогите разобраться в чем может быть дело.
В некоем файле есть блок, в котором задан атрибут с тагом
"LIST_NUMBER". При вставке этого блока в текущий документ, этот аттрибут пропадает. Вот код:
using System; using System.Collections.Generic; using System.Text; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using AcadApplic = Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Interop; using Autodesk.AutoCAD.Interop.Common; namespace Sapr { class Class1 { static void addFormat() { AcadApplic.Document doc = AcadApplic.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; string fname = @"C:\A3.dwg"; if (!System.IO.File.Exists(fname)) fname = HostApplicationServices.Current.FindFile(fname, doc.Database, FindFileHint.Default); using (Database db = new Database(false, false)) { //читаем файл форматки db.ReadDwgFile(fname, System.IO.FileShare.Read, true, null); using (Transaction t = doc.TransactionManager.StartTransaction()) { //вставляем в базу ObjectId idBTR = doc.Database.Insert("FormatA3", db, true); BlockTable bt = (BlockTable)t.GetObject(doc.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); try { using (BlockReference bref = new BlockReference(new Point3d(0, 0, 0), idBTR)) { btr.AppendEntity(bref); t.AddNewlyCreatedDBObject(bref, true); foreach (ObjectId id in bref.AttributeCollection) //коллекция всегда пуста!!! { Entity ent = (Entity)t.GetObject(id, OpenMode.ForWrite); if (ent is AttributeReference) { AttributeReference attRef = (AttributeReference)ent; if (attRef.Tag.ToUpper() == "LIST_NUMBER") { attRef.TextString = "some number"; } } } } } catch (System.Exception ex) { Helper.Message(ex); } t.Commit(); } } } } }