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

0 Members and 1 Guest are viewing this topic.

netcai

  • Mosquito
  • Posts: 12
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;

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: how to modify a viewport in paperspace?
« Reply #1 on: October 23, 2017, 07:55:07 PM »
I used this once, see the rest of the code here

Code - C#: [Select]
  1. using (ViewTable vt = (ViewTable)Application.DocumentManager.MdiActiveDocument.Database.ViewTableId.Open(OpenMode.ForWrite))
  2.                     {
  3.                         using (ViewTableRecord vtr = Application.DocumentManager.MdiActiveDocument.Editor.GetCurrentView())
  4.                         {
  5.                             vtr.SetUcs(syncView.ViewOrthographic);
  6.                             vtr.Target = syncView.Target;
  7.                             vtr.ViewDirection = syncView.ViewDirection;
  8.                             vtr.Elevation = syncView.Elevation;
  9.                             vtr.CenterPoint = syncView.CenterPoint;
  10.                             vtr.Height = syncView.Height;
  11.                             vtr.Width = syncView.Width;
  12.                             Application.DocumentManager.MdiActiveDocument.Editor.SetCurrentView(vtr);
  13.                             Application.DocumentManager.MdiActiveDocument.Editor.Regen();
  14.                         }
  15.                     }