Skip to main content
Glama

create_floors

Create multiple floors in Revit with automated unit conversion, floor type matching, and error handling. Supports batch creation of structural and non-structural floors based on boundary points and elevation.

Instructions

在Revit中创建楼板,支持批量创建,遵循JSON-RPC 2.0规范。 mcp_tool使用时params不要有任何注释信息

特性:

  • 支持批量创建多个楼板

  • 自动处理单位转换(毫米转英尺)

  • 自动匹配楼板类型或使用默认类型

  • 支持结构楼板和非结构楼板

  • 自动根据z值标高确定楼层

  • 完善的错误处理机制

参数: ctx (Context): FastMCP上下文对象 method (str): JSON-RPC方法名,默认为"CreateFloors" params (List[Dict]): 楼板参数列表,每个字典包含: - boundaryPoints (List[Dict]): 楼板边界点列表,每个点包含: - x (float): X坐标(毫米) - y (float): Y坐标(毫米) - z (float): Z坐标(毫米) - floorTypeName (str, optional): 楼板类型名称(可选) - structural (bool, optional): 是否为结构楼板(默认为False)

返回: 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 }

示例: # 创建多个楼板 response = create_floors(ctx, params=[ { "boundaryPoints": [ {"x": 0, "y": 0, "z": 0}, {"x": 5000, "y": 0, "z": 0}, {"x": 5000, "y": 5000, "z": 0}, {"x": 0, "y": 5000, "z": 0}, {"x": 0, "y": 0, "z": 0} ], "floorTypeName": "常规 - 150mm", "structural": True }, { "boundaryPoints": [ {"x": 0, "y": 0, "z": 3000}, {"x": 5000, "y": 0, "z": 3000}, {"x": 5000, "y": 5000, "z": 3000}, {"x": 0, "y": 5000, "z": 3000}, {"x": 0, "y": 0, "z": 3000} ], "floorTypeName": "常规 - 200mm" } ])

# 输出示例 { "jsonrpc": "2.0", "result": [213001, 213002], "id": 1 }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodNoCreateFloors
paramsNo

Implementation Reference

  • create_floors tool is included in the ARCHITECTURAL_TOOLS list used for registering MCP tools.
    ARCHITECTURAL_TOOLS = [ create_levels, create_floor_plan_views, create_grids, create_walls, create_floors, create_door_windows, create_rooms, create_room_tags, create_family_instances, create_sheets ]
  • The register_tools function loops over ARCHITECTURAL_TOOLS (including create_floors) and registers each as an MCP tool using server.tool().
    def register_tools(server: FastMCP) -> None: """注册所有工具到MCP服务器""" # 注册建筑工具 for tool in ARCHITECTURAL_TOOLS: server.tool()(tool)
  • Description of create_floors tool usage in the asset_creation_strategy prompt, indicating it creates floors with closed boundary points.
    - 使用create_floors()创建楼板,确保边界点形成封闭环路
  • Test data shows the expected input schema for create_floors: list of dicts with boundaryPoints (list of 3D points closing the loop), floorTypeName (str), structural (bool).
    data = [ { "boundaryPoints": [ {"x": 0.0, "y": 0.0, "z": 0.0}, {"x": 3000.0, "y": 0.0, "z": 0.0}, {"x": 3000.0, "y": 3000.0, "z": 0.0}, {"x": 0.0, "y": 3000.0, "z": 0.0}, {"x": 0.0, "y": 0.0, "z": 0.0} # 闭合边界 ], "floorTypeName": "常规 - 150mm", # 楼板类型名称 "structural": True # 表示该楼板为结构楼板 }, { "boundaryPoints": [ {"x": 0.0, "y": 0.0, "z": 0.0}, {"x": -5000.0, "y": 0.0, "z": 0.0}, {"x": -5000.0, "y": -5000.0, "z": 0.0}, {"x": 0.0, "y": 0.0, "z": 0.0} # 闭合边界 ], "floorTypeName": "常规 - 150mm", # 另一个楼板类型 "structural": False # 非结构楼板 } ]
  • RevitConnection.send_command is the core helper that tool handlers likely call with command_type='CreateFloors' and params from the tool input.
    def send_command(self, command_type: str, params: Union[Dict[str, Any], List[Dict[str, Any]]] = None) -> Dict[ str, Any]: """ 向Revit发送命令并返回响应 参数: command_type (str): 命令类型 params (Dict[str, Any] 或 List[Dict[str, Any]]): 命令参数 返回: Dict[str, Any]: 命令响应 异常: ConnectionError: 连接错误 TimeoutError: 请求超时 ValueError: 参数或响应无效 Exception: 其他错误 """ # 确保连接 if not self.sock and not self.connect(): raise ConnectionError("无法连接到Revit") try: logger.info(f"发送命令: {command_type}") logger.debug(f"命令参数: {params}") # 导入并创建请求对象 from .rpc import JsonRPCRequest, JsonRPCResponse command = JsonRPCRequest(method=command_type, params=params) command_json = json.dumps(command.__dict__) # 发送命令 self.sock.sendall(command_json.encode('utf-8')) logger.debug("命令已发送,等待响应...") # 使用 receive_full_response 接收完整数据流 response_data = self.receive_full_response() logger.debug(f"已接收 {len(response_data)} 字节数据") # 解析响应 try: response_dict = json.loads(response_data.decode('utf-8')) response = JsonRPCResponse( id=response_dict.get("id"), result=response_dict.get("result"), error=response_dict.get("error") ) except json.JSONDecodeError as e: logger.error(f"无法解析Revit响应: {str(e)}") if response_data: logger.error(f"原始响应 (前200字节): {response_data[:200]}") raise ValueError(f"无效的Revit响应: {str(e)}") # 处理错误 if response.error: error_message = response.error.get("message", "未知错误") error_code = response.error.get("code", -1) error_data = response.error.get("data") logger.error(f"Revit错误 (代码: {error_code}): {error_message}") if error_data: logger.error(f"错误数据: {error_data}") raise Exception(f"Revit错误: {error_message}") return response.result or {} except socket.timeout: self.sock = None raise TimeoutError("等待Revit响应超时 - 请尝试简化请求") except (ConnectionError, BrokenPipeError, ConnectionResetError) as e: self.sock = None raise ConnectionError(f"与Revit的连接丢失: {str(e)}") except json.JSONDecodeError as e: logger.error(f"Revit响应的JSON无效: {str(e)}") if 'response_data' in locals() and response_data: logger.error(f"原始响应 (前200字节): {response_data[:200]}") raise ValueError(f"Revit响应无效: {str(e)}") except (ValueError, TimeoutError, ConnectionError) as e: self.sock = None raise except Exception as e: logger.error(f"与Revit通信时出错: {str(e)}") self.sock = None raise Exception(f"与Revit通信错误: {str(e)}")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ZedMoster/revit-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server