简体   繁体   English

如何使用 Revit API 激活(显示)视图(平面图或标高)?

[英]How can I activate (display) a view (floor plan or Level) using Revit API?

I am trying to activate a view using Revit API.我正在尝试使用 Revit API 激活视图。 What I want to do exactly is to display the level or floor plan view.我想要做的正是显示水平或平面图视图。 So the view I want to activate ( I mean, I want this view to be actually shown on screen) already exists, and I can access its Id.所以我想激活的视图(我的意思是,我希望这个视图实际显示在屏幕上)已经存在,我可以访问它的 Id。

I have seen threads about creating, browsing, filtering views, but nothing on activating it... It's a Floor Plan view.我看到过关于创建、浏览、过滤视图的线程,但没有激活它......这是一个平面图视图。 (What I want is that by selecting a level/ floor plan, it displays that level/ floor plan on-screen(it's like opening that floor plan from the already existing Revit model to display on the user screen). (我想要的是,通过选择一个楼层/楼层平面图,它会在屏幕上显示该楼层/楼层平面图(就像从现有的 Revit 模型中打开该楼层平面图以显示在用户屏幕上)。

Here is an example how to switch to the default 3d-view https://thebuildingcoder.typepad.com/blog/2011/09/activate-a-3d-view.html这是一个如何切换到默认 3d 视图的示例https://thebuildingcoder.typepad.com/blog/2011/09/activate-a-3d-view.html

you can do the same with all other available views like this您可以对所有其他可用视图执行相同的操作

    UIApplication uiapp = commandData.Application;
    UIDocument uidoc = uiapp.ActiveUIDocument;
  
    uidoc.ActiveView = yourview;

Super easy to do:超级容易做到:

# normally you have the ui set at the start of your script
ui = __revit__.ActiveUIDocument 

# then just set the ActiveView as your view (not the ViewId)
ui.ActiveView = yourView

FilteredElementCollector viewCollector = new FilteredElementCollector(doc); FilteredElementCollector viewCollector = new FilteredElementCollector(doc);

                viewCollector.OfClass(typeof(View));

                foreach (Element viewElement in viewCollector)
                {
                        yourview = (View)viewElement;
                      
                        break;  
                }
            }

            uidoc.ActiveView = yourview;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM