- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i have a routine that opens a drawing with a block that contains attributes and then updated some of the attributes. my issue is when i have the routine open the drawing and modify the attributes. they don't display unless you dbl click on the block and then the attributes are justified wrong. when i comment out the .Open and manually open the file the rest of the routine works fine. i am at a loss.
public static void GenerateDESD()
{
string FileLocation = @"\\fserve01\cad$\Auto_temps\double end stud.DWG";
Autodesk.AutoCAD.ApplicationServices.DocumentCollection DocColdesd
= Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
Autodesk.AutoCAD.ApplicationServices.DocumentCollection docCol = DocColdesd;
Document acDoc = Autodesk.AutoCAD.ApplicationServices.DocumentCollectionExtension.Open(docCol, FileLocation, false);
DocColdesd.MdiActiveDocument = acDoc;
Editor ed = acDoc.Editor;
Database db = acDoc.Database;
using (var lk = acDoc.LockDocument())
{
using (Transaction Tx = acDoc.Database.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)Tx.GetObject(acDoc.Database.BlockTableId, OpenMode.ForRead, true);
BlockTableRecord btr = (BlockTableRecord)Tx.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
foreach (ObjectId bref in btr)
{
if (bref.ObjectClass.Name == "AcDbBlockReference")
{
BlockReference currentBlockRef = Tx.GetObject(bref, OpenMode.ForRead) as BlockReference;
if (currentBlockRef.Name == "DESD")
{
foreach (ObjectId arId in currentBlockRef.AttributeCollection)
{
DBObject obj =Tx.GetObject(arId,OpenMode.ForWrite );
AttributeReference ar = obj as AttributeReference;
if (ar != null)
{
if (ar.Tag.ToUpper() == "8")
{
ar.TextString = "test"; //just updating one attribute for this example
}
}
}
Tx.Commit();
}
}
}
}
}
}
Solved! Go to Solution.