Author Topic: how to modify a viewport in paperspace?  (Read 40 times)

0 Members and 1 Guest are viewing this topic.

netcai

  • Mosquito
  • Posts: 8
how to modify a viewport in paperspace?
« on: October 17, 2017, 08:53:01 pm »
I try to change a viewport's property,but the code always crashed at the tr.Commit();

Code: [Select]
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;