You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Revit API激活并显示已有的楼层平面或标高视图

Revit API激活楼层平面视图实现方案

当你已经获取到目标楼层平面视图的Id时,仅需通过UIDocument的ActiveView属性赋值即可完成视图激活,效果等同于用户手动点击打开对应楼层平面。

实现步骤

  • 引入Revit UI相关命名空间Autodesk.Revit.UI,视图激活属于UI层操作,需使用UIDocument而非仅文档对象Document
  • 校验目标Id对应的元素为有效楼层平面视图:判断视图类型为ViewType.FloorPlan,且IsViewValid属性为真,避免无效赋值抛出异常
  • 直接将目标视图实例赋值给UIDocument.ActiveView即可完成激活,无需额外操作

代码示例

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
    UIDocument uidoc = commandData.Application.ActiveUIDocument;
    Document doc = uidoc.Document;
    
    // 替换为你实际获取到的目标楼层平面视图Id
    ElementId targetViewId = new ElementId(123456); 
    View targetFloorPlan = doc.GetElement(targetViewId) as View;
    
    // 视图合法性校验
    if (targetFloorPlan == null 
        || targetFloorPlan.ViewType != ViewType.FloorPlan 
        || !targetFloorPlan.IsViewValid)
    {
        message = "目标Id对应视图不是有效的楼层平面";
        return Result.Failed;
    }
    
    // 核心激活代码
    uidoc.ActiveView = targetFloorPlan;
    
    return Result.Succeeded;
}

注意:修改ActiveView属于UI层操作,不属于文档修改范畴,不需要开启事务(Transaction)即可执行。

内容的提问来源于stack exchange,提问作者Abhijit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 11:30:01