我正在尝试使用 Revit API 激活视图。我想要做的就是显示楼层或平面图视图。所以我想要激活的视图(我的意思是,我希望这个视图实际显示在屏幕上)已经存在,并且我可以访问它的 Id。
我看过有关创建、浏览、过滤视图的线程,但没有看到有关激活它的内容......这是一个平面图视图。 (我想要的是,通过选择一个楼层/平面图,它会在屏幕上显示该楼层/平面图(就像从现有的 Revit 模型中打开该平面图以显示在用户屏幕上一样)。
超级容易做:
# 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
这里是如何切换到默认 3D 视图的示例 https://thebuildingcoder.typepad.com/blog/2011/09/activate-a-3d-view.html
您可以对所有其他可用视图执行相同的操作,如下所示
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
uidoc.ActiveView = yourview;
要从某个级别创建视图,您的代码可以如下所示
ViewFamilyType viewFamilyType = (from elem in new
FilteredElementCollector(doc)
.OfClass(typeof(ViewFamilyType))
let type = elem as ViewFamilyType
where type.ViewFamily == ViewFamily.FloorPlan
select type).FirstOrDefault();
using (Transaction t = new Transaction(doc))
{
t.Start("Create View");
var floorPlan = ViewPlan.Create(doc, viewFamilyType.Id, yourLevel.Id);
floorPlan.Name = "NewView";
t.Commit();
}
FilteredElementCollector viewCollector = new FilteredElementCollector(doc);
viewCollector.OfClass(typeof(View));
foreach (Element viewElement in viewCollector)
{
yourview = (View)viewElement;
break;
}
}
uidoc.ActiveView = yourview;
RequestViewChange 方法的 Revit api 文档链接
使用
uidoc.RequestViewChange("Your View")
有时在处理交易时无法更改视图。在这种情况下,强制关闭交易。在这行之前 uidoc.RequestViewChange("Your View")