我正在尝试使用 Revit API 激活视图。我想要做的是显示水平或平面图视图。所以我要激活的视图(我的意思是,我希望这个视图实际显示在屏幕上)已经存在,我可以访问它的 ID。
我已经看到有关创建、浏览、过滤视图的线程,但没有激活它……这是一个平面图视图。(我想要的是通过选择一个级别/平面图,它会在屏幕上显示该级别/平面图(就像从现有的 Revit 模型中打开该平面图以显示在用户屏幕上一样)。
我正在尝试使用 Revit API 激活视图。我想要做的是显示水平或平面图视图。所以我要激活的视图(我的意思是,我希望这个视图实际显示在屏幕上)已经存在,我可以访问它的 ID。
我已经看到有关创建、浏览、过滤视图的线程,但没有激活它……这是一个平面图视图。(我想要的是通过选择一个级别/平面图,它会在屏幕上显示该级别/平面图(就像从现有的 Revit 模型中打开该平面图以显示在用户屏幕上一样)。
这是一个如何切换到默认 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;
超级容易做到:
# 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