Revit二次开发中如何切换到3D视图

我们在Revit二次开发中使用过滤器等一些操作的时候通常要固定在某一个视图中,分享一个切换到3D视图的方法,当然切换到其他的2D视图也是同样道理
 

        /// <summary>
        /// 将当前视图切换到三维视图
        /// </summary>
        /// <param name="uidoc"></param>
        public void SwitchTo3DView(UIDocument uidoc, Transaction transation)
        {
            Document document = uidoc.Document;

            //查看当前视图是否为3D视图
            var type = document.ActiveView.GetType();
            if (!typeof(View3D).Equals(type))
            {
                View3D view3D = null;

                //查看当前文件有没有3D视图
                FilteredElementCollector fristCollector = new FilteredElementCollector(document).OfClass(typeof(View3D));
                foreach (View3D view in fristCollector)
                {
                    if ("{三维}".Equals(view.Name))
                    {
                        view3D = view;
                        break;
                    }
                }

                //如果没有找到3D视图,创建一个
                if (view3D == null)
                {
                    //过滤出三维视图
                    ElementId viewFamilyTypeId = new ElementId(0);
                    FilteredElementCollector secondCollector = new                        FilteredElementCollector(document).OfClass(typeof(ViewFamilyType));
                    foreach (ViewFamilyType viewFamilyType in secondCollector.ToList())
                    {
                        if ("三维视图".Equals(viewFamilyType.Name))
                        {
                            transation.Start("新建三维视图");
                            view3D = View3D.CreateIsometric(document, viewFamilyType.Id);
                            transation.Commit();
                            break;
                        }
                    }
                }

                //切换到三维视图
                uidoc.ActiveView = view3D;
            }

        }

猜你喜欢

转载自blog.csdn.net/baidu_27922823/article/details/85103278