get_view_data
Extract all text and graphical entity data from the current Revit view, including text content with positions and geometric information for lines, arcs, and circles, organized by layers in JSON-RPC format.
Instructions
读取当前视图中所有信息,包括文本和图形实体数据,遵循JSON-RPC 2.0规范。
特性:
提取所有文本内容及其位置信息
提取所有图形对象(线、弧、圆等)的几何信息
按图层组织返回的数据
完善的错误处理机制
参数: ctx (Context): FastMCP上下文对象 method (str): JSON-RPC方法名,默认为"GetViewData" params (List[dict], optional): 可选参数,默认为None
返回: dict: JSON-RPC 2.0格式的响应,结构为: 成功时: { "jsonrpc": "2.0", "result": [ { "name": "图层名称", "type": "Text", "text": "文本内容", "point": {"X": x值, "Y": y值, "Z": z值} }, { "name": "图层名称", "type": "Line", "startPoint": {"X": x1, "Y": y1, "Z": z1}, "endPoint": {"X": x2, "Y": y2, "Z": z2} }, { "name": "图层名称", "type": "Arc", "startAngle": 起始角度, "endAngle": 结束角度, "centerPoint": {"X": x, "Y": y, "Z": z}, "radius": 半径值 }, { "name": "图层名称", "type": "Circle", "centerPoint": {"X": x, "Y": y, "Z": z}, "radius": 半径值 }, ... ], "id": request_id } 失败时: { "jsonrpc": "2.0", "error": { "code": int, "message": str, "data": any }, "id": request_id }
错误代码: -32600: 无效请求 -32603: 内部错误(导出或解析时) -32700: 解析错误
示例: # 获取当前视图所有图形数据 response = get_view_data(ctx)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| method | No | GetViewData | |
| params | No |
Implementation Reference
- xml_revit_mcp/server.py:50-55 (registration)get_view_data is listed in GENERAL_TOOLS for registration as an MCP tool.GENERAL_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-146 (registration)The register_tools function registers get_view_data and other general tools to the FastMCP server using the @tool decorator.# 注册通用工具 for tool in GENERAL_TOOLS: server.tool()(tool)
- xml_revit_mcp/server.py:248-248 (registration)Call to register_tools which includes registration of get_view_data.register_tools(mcp)
- xml_revit_mcp/server.py:58-95 (helper)Global helper to obtain persistent RevitConnection instance, likely used within tool handlers like get_view_data.def get_revit_connection() -> RevitConnection: """ 获取或创建持久的Revit连接 返回: RevitConnection: 与Revit的连接对象 异常: Exception: 连接失败时抛出 """ global _connection, _enabled if _connection is not None: try: # 测试连接是否有效 result = _connection.send_command("get_polyhaven_status") _enabled = result.get("enabled", False) return _connection except Exception as e: logger.warning(f"现有连接已失效: {str(e)}") try: _connection.disconnect() except: pass _connection = None # 创建新连接 if _connection is None: _connection = RevitConnection(host="localhost", port=_port) if not _connection.connect(): logger.error("无法连接到Revit") _connection = None raise Exception( "无法连接到Revit。请确保Revit插件正在运行。") logger.info("已创建新的持久连接到Revit") return _connection