Database currentDatabase = HostApplicationServices.WorkingDatabase;
Database db = new Database(false, true);
db.ReadDwgFile(item.FileName, FileShare.ReadWrite, true, null);
HostApplicationServices.WorkingDatabase = db;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectId layoutId = Arx.SymTbl.GetDictionaryObject(item.LayoutName, db.LayoutDictionaryId, tr);
Layout layout = (Layout)tr.GetObject(layoutId, OpenMode.ForWrite);
BlockTableRecord psbtr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);
foreach (ObjectId id in psbtr)
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
if (ent is Viewport && id != db.PaperSpaceVportId)
{
Viewport vp = ent as Viewport;
vp.Width = item.ViewPortPsWidth;
vp.Height = item.ViewPortPsHeight;
vp.CenterPoint = item.ViewPortPsCentePnt;
vp.ViewCenter = item.ViewPortMsViewCenterPnt;
vp.CustomScale = 1 / item.Scale;
}
}
tr.Commit(); stop here
}
db.SaveAs(item.FileName, DwgVersion.Current);
HostApplicationServices.WorkingDatabase = currentDatabase;