get_elements
Retrieve elements from Revit models by specifying categories, views, or levels to access and analyze building information data.
Instructions
获取 Revit 模型中的元素
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| categoryIds | No | 需要获取的元素所属类别的Id集合 | |
| viewIds | No | 需要获取的元素所处的视图的Id集合 | |
| levelIds | No | 需要获取的元素所处的标高的Id集合 |
Implementation Reference
- src/index.ts:140-158 (registration)Registration of the 'get_elements' tool including name, description, and input schema in ListToolsRequestSchema.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/index.ts:207-220 (handler)Dynamic dispatching in CallToolRequestSchema handler that maps 'get_elements' to revitService.getElements and invokes it.// 将工具名称转换为 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 || {});
- src/revitService.ts:54-63 (handler)Core handler method in RevitService that forwards get_elements request to the RevitSocketClient.async getElements(args: GetElementsArgs): Promise<RevitElement[]> { try { return await this.client.getElements(args); } catch (error) { console.error('[RevitService] 获取元素失败,使用模拟数据:', error); throw error; // 不使用模拟数据,直接抛出错误 } }
- src/revitSocketClient.ts:203-206 (helper)Socket client method that sends the 'get_elements' command with arguments to the Revit plugin.public async getElements(args: GetElementsArgs): Promise<RevitElement[]> { const response = await this.sendRequest<RevitElement[]>('get_elements', args); return response; }
- src/types.ts:19-25 (schema)Type definition for GetElementsArgs used in the handler signatures.export interface GetElementsArgs { category?: string; family?: string; type?: string; level?: string; limit?: number; }