netcai 发表于 2017-10-17 20:53:01

如何在图纸空间中修改视口?

我试图更改视口的属性,但代码总是在tr处崩溃。Commit();
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;

**** Hidden Message *****

魔兽ㄇ 发表于 2017-10-23 19:55:07

我使用过一次,请参阅此处的其余代码<br>使用(ViewTable vt=(ViewTable)Application.DocumentManager.MdiActiveDocument.Database.ViewTableId.Open(OpenMode.ForWrite))<ol><div>
{
使用(ViewTableRecord vtr=Application.DocumentManager.MdiActiveDocument.Editor.GetCurrentView())
{
vtr.SetUcs(syncView.ViewOrthographic)
录像机。Target=syncView.Target
录像机。ViewDirection=syncView.ViewDirection
录像机。标高=syncView.Elevation
录像机。中心点=syncView.CenterPoint
录像机。高度=syncView.Height
录像机。宽度=syncView.Width
应用程序.DocumentManager.MdiActiveDocument.Editor.SetCurrentView(vtr)
Application.DocumentManager.MdiActiveDocument.Editor.Regen()
}
}
页: [1]
查看完整版本: 如何在图纸空间中修改视口?