get_selected_elements
Retrieve currently selected elements in Revit with optional limit on the number of returned elements for efficient project management and analysis.
Instructions
Get elements currently selected in Revit. You can limit the number of returned elements.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of elements to return |
Implementation Reference
- src/tools/get_selected_elements.ts:15-45 (handler)The handler function that implements the core logic of the 'get_selected_elements' MCP tool. It prepares parameters, sends the command to the Revit client using withRevitConnection, and formats the response or error.async (args, extra) => { const params = { limit: args.limit || 100, }; try { const response = await withRevitConnection(async (revitClient) => { return await revitClient.sendCommand("get_selected_elements", params); }); return { content: [ { type: "text", text: JSON.stringify(response, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `get selected elements failed: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- Input schema definition using Zod, defining an optional 'limit' parameter for the number of elements to retrieve.limit: z .number() .optional() .describe("Maximum number of elements to return"), },
- src/tools/get_selected_elements.ts:5-47 (registration)The registration function for the 'get_selected_elements' tool, which is dynamically discovered and invoked by src/tools/register.ts to add the tool to the MCP server.export function registerGetSelectedElementsTool(server: McpServer) { server.tool( "get_selected_elements", "Get elements currently selected in Revit. You can limit the number of returned elements.", { limit: z .number() .optional() .describe("Maximum number of elements to return"), }, async (args, extra) => { const params = { limit: args.limit || 100, }; try { const response = await withRevitConnection(async (revitClient) => { return await revitClient.sendCommand("get_selected_elements", params); }); return { content: [ { type: "text", text: JSON.stringify(response, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `get selected elements failed: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } ); }