active_view
Activate and open views in Revit using JSON-RPC 2.0, supporting single or multiple views with element validation and error handling for efficient model navigation.
Instructions
激活并打开Revit中的视图,遵循JSON-RPC 2.0规范。 mcp_tool使用时params不要有任何注释信息
特性:
支持打开单个或多个视图
自动验证视图元素有效性
过滤模板视图
完善的错误处理机制
参数: ctx (Context): FastMCP上下文对象 method (str): JSON-RPC方法名,默认为"ActiveView" params (List[Dict]): 视图参数列表,每个字典包含: - elementId (Union[int, str]): 视图元素ID
返回: dict: JSON-RPC 2.0格式的响应,结构为: 成功时: { "jsonrpc": "2.0", "result": [ { "elementId": "视图元素ID", "name": "视图名称", "familyName": "视图族名称" }, ... ], "id": request_id } 失败时: { "jsonrpc": "2.0", "error": { "code": int, "message": str, "data": any }, "id": request_id }
错误代码: -32600: 无效请求 -32602: 无效参数(元素不是视图/是模板视图/无效元素) -32603: 内部错误 -32700: 解析错误
示例: # 激活单个视图 response = active_view(ctx, params=[{"elementId": 123456}])
注意: 1. 无法激活模板视图(会返回错误) 2. 如果传入多个视图ID,会依次尝试激活,最后一个成功的视图将成为当前视图 3. 返回的列表包含所有成功激活的视图ID
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| method | No | ActiveView | |
| params | No |
Implementation Reference
- xml_revit_mcp/server.py:50-55 (registration)active_view is included in GENERAL_TOOLS list of functions to be registered as MCP toolsGENERAL_TOOLS = [ get_commands, execute_commands, call_func, find_elements, update_elements, delete_elements, parameter_elements, get_locations, move_elements, show_elements, active_view, get_selected_elements, link_dwg_and_activate_view, get_view_data ]
- xml_revit_mcp/server.py:144-147 (registration)register_tools function registers each tool in GENERAL_TOOLS, including active_view, using server.tool() decorator# 注册通用工具 for tool in GENERAL_TOOLS: server.tool()(tool)
- xml_revit_mcp/server.py:248-248 (registration)Call to register_tools(mcp) which registers the active_view toolregister_tools(mcp)
- tests/ActiveView.py:6-20 (helper)Test script demonstrating the RPC call to ActiveView method with parameters, indicating the backend RPC method name used by the tooldata = [ {"elementId": 4664, }, {"elementId": "2307", } ] # 构造 JSON-RPC 请求 json_rpc_request = { "jsonrpc": "2.0", "method": "ActiveView", "params": data, } # 发送更新元素数据 send_tcp_data(json_rpc_request)
- xml_revit_mcp/prompts.py:46-46 (helper)Prompt documentation referencing usage of active_view() tool to switch views- 使用active_view()切换到需要的视图