get_elements
Extract specific elements from a Revit model by specifying category, view, or level IDs using the Revit MCP Server API for precise data retrieval.
Instructions
获取 Revit 模型中的元素
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| categoryIds | No | 需要获取的元素所属类别的Id集合 | |
| levelIds | No | 需要获取的元素所处的标高的Id集合 | |
| viewIds | No | 需要获取的元素所处的视图的Id集合 |
Implementation Reference
- src/revitSocketClient.ts:203-206 (handler)Core handler implementation for the `get_elements` tool: sends the `get_elements` command with arguments to the Revit plugin via socket request.public async getElements(args: GetElementsArgs): Promise<RevitElement[]> { const response = await this.sendRequest<RevitElement[]>('get_elements', args); return response; }
- src/revitService.ts:54-63 (handler)MCP tool handler proxy for `get_elements`: delegates execution to the socket client.async getElements(args: GetElementsArgs): Promise<RevitElement[]> { try { return await this.client.getElements(args); } catch (error) { console.error('[RevitService] 获取元素失败,使用模拟数据:', error); throw error; // 不使用模拟数据,直接抛出错误 } }
- src/index.ts:201-239 (registration)Generic MCP CallTool handler that dynamically invokes `revitService.getElements()` for tool name `get_elements`.this.server.setRequestHandler( CallToolRequestSchema, async (request) => { // 获取工具名称 const toolName = request.params.name; // 将工具名称转换为 camelCase 方法名 const methodName = toolName.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()); // 检查 RevitService 是否有对应的方法 if (typeof (this.revitService as any)[methodName] !== 'function') { throw new McpError( ErrorCode.MethodNotFound, `未知工具: ${toolName}` ); } try { // 动态调用对应的方法 const result = await (this.revitService as any)[methodName](request.params.arguments || {}); //const result = ''; return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Revit API 错误: ${error instanceof Error ? error.message : String(error)}` }], isError: true, } } } ); }
- src/index.ts:140-158 (registration)Registers the `get_elements` tool in MCP ListTools response, including name, description, and input schema.name: "get_elements", description: "获取 Revit 模型中的元素", inputSchema: { type: "object", properties: { categoryIds: { type: "array", description: "需要获取的元素所属类别的Id集合" }, viewIds: { type: "array", description: "需要获取的元素所处的视图的Id集合" }, levelIds: { type: "array", description: "需要获取的元素所处的标高的Id集合" } } }
- src/types.ts:19-25 (schema)TypeScript interface defining input arguments for `get_elements` tool (note: slightly differs from runtime schema).export interface GetElementsArgs { category?: string; family?: string; type?: string; level?: string; limit?: number; }