以下代码不会更新属性,也无法确定我的属性未更新的原因。
案例陈述肯定受到打击,因此出于某种原因我的更改未提交给数据库。
Database db = new Database(false, true);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
db.ReadDwgFile(fileName, System.IO.FileShare.Read, false, "");
db.CloseInput(true);
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec = tr.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite) as BlockTableRecord;
foreach (ObjectId id in acBlkTblRec)
{
DBObject obj = tr.GetObject(id, OpenMode.ForRead);
BlockReference blkRef = obj as BlockReference;
if (blkRef != null)
{
AttributeCollection attCol = blkRef.AttributeCollection;
foreach (ObjectId objID in attCol)
{
DBObject dbObj = tr.GetObject(objID, OpenMode.ForWrite) as DBObject;
AttributeReference acAttRef = dbObj as AttributeReference;
switch (acAttRef.Tag)
{
case "DRAWINGTITLE1":
acAttRef.TextString = controllerName;
break;
case "DATE1":
case "DATE4":
case "XX_XX_XX":
acAttRef.TextString = DateTime.Now.ToShortDateString();
break;
case "DW1":
case "CK1":
case "XXX":
acAttRef.TextString = userSuffix;
break;
default:
break;
}
}
}
}
tr.Commit();
}