Skip to main content
Glama
ZedMoster

Revit MCP Server

by ZedMoster

get_selected_elements

Retrieve currently selected elements in Revit UI with IDs, categories, and names using JSON-RPC 2.0 format for automation workflows.

Instructions

获取当前Revit UI中选择的元素,遵循JSON-RPC 2.0规范。

特性:

  • 获取当前用户在Revit界面中选择的所有元素

  • 返回元素的完整信息,包括ID、类别和名称

  • 无需额外参数,直接反映当前UI状态

  • 完善的错误处理机制

参数: ctx (Context): FastMCP上下文对象 method (str): JSON-RPC方法名,默认为"GetSelectedElements"

返回: 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 = get_selected_elements(ctx)

# 输出示例
{
    "jsonrpc":"2.0","id":"a39934f6-0ee9-4319-b820-1eba95a82c51",
    "result":
    [
        {"elementId":"355","familyName":"标高","name":"标高 1"},
        {"elementId":"2607","familyName":"标高","name":"标高 2"},
        {"elementId":"5855","familyName":"标高","name":"T.O. Fnd. 墙"}
    ],
    "error":[]
}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodNoGetSelectedElements

Implementation Reference

  • The tool 'get_selected_elements' is included in the GENERAL_TOOLS list, which is registered to the MCP server.
    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
    ]
  • The register_tools function registers all tools in GENERAL_TOOLS (including get_selected_elements) using server.tool() decorator.
    def register_tools(server: FastMCP) -> None:
        """注册所有工具到MCP服务器"""
        # 注册建筑工具
        for tool in ARCHITECTURAL_TOOLS:
            server.tool()(tool)
    
        # 注册MEP工具
        for tool in MEP_TOOLS:
            server.tool()(tool)
    
        # 注册通用工具
        for tool in GENERAL_TOOLS:
            server.tool()(tool)
  • Test script demonstrating the JSON-RPC call to the Revit plugin for 'GetSelectedElements', likely corresponding to the MCP tool logic.
    # -*- coding: utf-8 -*-
    
    from _tcp import send_tcp_data
    
    # 构造 JSON-RPC 请求
    json_rpc_request = {
        "jsonrpc": "2.0",
        "method": "GetSelectedElements",
        "params": {},
    }
    
    # 发送更新元素数据
    send_tcp_data(json_rpc_request)
  • The tool is referenced in the asset_creation_strategy prompt docstring.
    - 使用get_commands()获取所有可用功能
    - 使用get_selected_elements()检查当前选中的元素

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