modify attributes

modify attributes

bherber
Contributor Contributor
1,219 Views
4 Replies
Message 1 of 5

modify attributes

bherber
Contributor
Contributor

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();
}
}
}
}
}

}

0 Likes
Accepted solutions (1)
1,220 Views
4 Replies
Replies (4)
Message 2 of 5

jeff
Collaborator
Collaborator

Have you tried?

ar.AdjustAlignment(db);
You can also find your answers @ TheSwamp
0 Likes
Message 3 of 5

bherber
Contributor
Contributor

it didnt make any difference. what is odd is the method works fine if you manually open the drawing but if you let the code open the drawing, that is when the issues suraface.

0 Likes
Message 4 of 5

CADbloke
Advocate
Advocate
Accepted solution
http://adndevblog.typepad.com/autocad/2012/07/using-readdwgfile-with-net-attachxref-or-objectarx-acd... may be helpful And check this too. http://adndevblog.typepad.com/autocad/2012/07/using-readdwgfile-with-net-attachxref-or-objectarx-acd...

I had similar issues, you use HostApplicationServices.WorkingDatabase but you have to be careful with it. We have found that ar.AdjustAlignment(db); doesn't work if it is not the working database.
- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
0 Likes
Message 5 of 5

CADbloke
Advocate
Advocate
Glad my answer helped. Here's some more info on this problem ... http://forums.autodesk.com/t5/net/attribute-alignment/m-p/3182842#M25497
- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
0 Likes