Code Red > .NET

how to modify a viewport in paperspace?

(1/1)

netcai:
I try to change a viewport's property,but the code always crashed at the tr.Commit();


--- Code: --- 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;

--- End code ---

WILL HATCH:
I used this once, see the rest of the code here


--- Code - C#: ---using (ViewTable vt = (ViewTable)Application.DocumentManager.MdiActiveDocument.Database.ViewTableId.Open(OpenMode.ForWrite))                    {                        using (ViewTableRecord vtr = Application.DocumentManager.MdiActiveDocument.Editor.GetCurrentView())                        {                            vtr.SetUcs(syncView.ViewOrthographic);                            vtr.Target = syncView.Target;                            vtr.ViewDirection = syncView.ViewDirection;                            vtr.Elevation = syncView.Elevation;                            vtr.CenterPoint = syncView.CenterPoint;                            vtr.Height = syncView.Height;                            vtr.Width = syncView.Width;                            Application.DocumentManager.MdiActiveDocument.Editor.SetCurrentView(vtr);                            Application.DocumentManager.MdiActiveDocument.Editor.Regen();                        }                    }

Navigation

[0] Message Index

Go to full version