jiheng 发表于 2010-5-4 00:22:00

[求助]在图纸空间创建浮动视口的问题

//下面的代码在图形空间创建了一个浮动视口,但要如何实现下面几项功能还要请高手指教。
      //1. 如何将视口设置为等轴测视图,如西南视图
      //2. 如何在视口内最大化显示指定的实体
      //3. 如何在视口内冻结指定的图层
      public void vp()
      {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                Viewport vp = new Viewport();
                vp.CenterPoint = new Point3d(0,0,0);
                vp.Width = 30;
                vp.Height = 40;               
               
                BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);
                btr.AppendEntity(vp);
                trans.AddNewlyCreatedDBObject(vp,true);
                //激活视口
                vp.On = true;
                //设置视口的视图
                vp.SetViewDirection(OrthographicView.LeftView);//OrthographicView只有正交视图的参数,要如何设置为等轴测视图呢?如西南视图...
                vp.SetShadePlot(ShadePlotType.Hidden, vp.Id);//第二个参数我用vp.Id是我瞎猜的,虽然编译通过,但具体什么意思我还不明白
                //设置要冻结的图层我猜过去一定是用FreezeLayersInViewport方法,但这个方法所需要的参数却不知道要怎样写.
                //vp.FreezeLayersInViewport(???)
                trans.Commit();
            }
            
      }

jiheng 发表于 2010-5-4 09:28:00

解决了第3个问题 下面的代码可以在视口内冻结0层以外的图层
                //下面的代码可以在视口内冻结0层以外的图层
                LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite);
                ObjectIdCollection ids = new ObjectIdCollection();
                foreach (ObjectId id in lt)
                {
                  LayerTableRecord ltr = (LayerTableRecord)trans.GetObject(id, OpenMode.ForRead);
                  if (ltr.Name != "0")
                  {
                        ids.Add(id);
                  }
                }
            
                vp.FreezeLayersInViewport(ids.GetEnumerator());

雪山飞狐_lzh 发表于 2010-5-4 13:57:00

参考下这里
不过视口的缩放好像不太一样,kean的博客有看到类似的代码
视图方向应该是更改当前视图的扭转角等的途径实现吧

jiheng 发表于 2010-5-5 19:05:00

解决了第1个问题,原来只要下面这一行代码就可以将视口设置为西南等轴测视图
vp.ViewDirection = new Vector3d(-1, -1, 1);
页: [1]
查看完整版本: [求助]在图纸空间创建浮动视口的问题