Open-source Revit MCP server: let Claude and other AI assistants read and edit BIM models, with human approval on every change.
Python aecai-agentsautodeskautomationbimclaudeifcmcpmcp-servermodel-context-protocolnavisworksrevitrevit-addinrevit-apirhino
feat: Add Revit MCP server and C# bridge add-in to enable programmatic Revit control via tools.
A. Sam Mohammad3ddf7364d5b3
diff --git a/build_log.txt b/build_log.txtnew file mode 100644index 0000000..d2353b5Binary files /dev/null and b/build_log.txt differdiff --git a/packages/mcp-server-revit/src/revit_mcp_server/mcp_server.py b/packages/mcp-server-revit/src/revit_mcp_server/mcp_server.pyindex 8610527..af1d1c7 100644--- a/packages/mcp-server-revit/src/revit_mcp_server/mcp_server.py+++ b/packages/mcp-server-revit/src/revit_mcp_server/mcp_server.py@@ -440,7 +440,36 @@ async def list_tools() -> list[Tool]:"required": ["start_number"]}),- ]++ # Batch 2: Selection+ Tool(name="revit_get_selection", description="Get currently selected element IDs", inputSchema={"type": "object", "properties": {}}),+ Tool(name="revit_set_selection", description="Set selection by element IDs", inputSchema={"type": "object", "properties": {"element_ids": {"type": "array", "items": {"type": "integer"}}}, "required": ["element_ids"]}),++ # Batch 2: Annotation+ Tool(name="revit_create_text_note", description="Create a text note", inputSchema={"type": "object", "properties": {"text": {"type": "string"}, "x": {"type": "number"}, "y": {"type": "number"}, "view_id": {"type": "integer"}}, "required": ["text", "x", "y"]}),+ Tool(name="revit_create_tag", description="Tag an element", inputSchema={"type": "object", "properties": {"element_id": {"type": "integer"}, "x": {"type": "number"}, "y": {"type": "number"}, "view_id": {"type": "integer"}}, "required": ["element_id", "x", "y"]}),++ # Batch 2: Structure+ Tool(name="revit_create_column", description="Create structural column", inputSchema={"type": "object", "properties": {"family_name": {"type": "string"}, "type_name": {"type": "string"}, "level": {"type": "string"}, "x": {"type": "number"}, "y": {"type": "number"}}, "required": ["family_name", "type_name", "level", "x", "y"]}),+ Tool(name="revit_create_beam", description="Create structural beam", inputSchema={"type": "object", "properties": {"family_name": {"type": "string"}, "type_name": {"type": "string"}, "level": {"type": "string"}, "start_x": {"type": "number"}, "start_y": {"type": "number"}, "end_x": {"type": "number"}, "end_y": {"type": "number"}}, "required": ["family_name", "type_name", "level", "start_x", "start_y", "end_x", "end_y"]}),+ Tool(name="revit_create_foundation", description="Create foundation", inputSchema={"type": "object", "properties": {"family_name": {"type": "string"}, "type_name": {"type": "string"}, "level": {"type": "string"}, "x": {"type": "number"}, "y": {"type": "number"}, "z": {"type": "number", "default": 0}}, "required": ["family_name", "type_name", "level", "x", "y"]}),++ # Batch 2: MEP+ Tool(name="revit_create_duct", description="Create duct", inputSchema={"type": "object", "properties": {"level": {"type": "string"}, "start_x": {"type": "number"}, "start_y": {"type": "number"}, "end_x": {"type": "number"}, "end_y": {"type": "number"}, "z": {"type": "number", "default": 10}, "system_type": {"type": "string"}, "duct_type": {"type": "string"}}, "required": ["level", "start_x", "start_y", "end_x", "end_y"]}),+ Tool(name="revit_create_pipe", description="Create pipe", inputSchema={"type": "object", "properties": {"level": {"type": "string"}, "start_x": {"type": "number"}, "start_y": {"type": "number"}, "end_x": {"type": "number"}, "end_y": {"type": "number"}, "z": {"type": "number", "default": 0}, "system_type": {"type": "string"}, "pipe_type": {"type": "string"}}, "required": ["level", "start_x", "start_y", "end_x", "end_y"]}),++ # Batch 2: Helpers+ Tool(name="revit_get_categories", description="List Revit categories", inputSchema={"type": "object", "properties": {}}),+ Tool(name="revit_get_element_type", description="Find element types/families", inputSchema={"type": "object", "properties": {"category_name": {"type": "string"}, "family_name": {"type": "string"}}, "required": ["category_name"]}),++ # Batch 2: Remaining Existing+ Tool(name="revit_close_document", description="Close active document", inputSchema={"type": "object", "properties": {"save_changes": {"type": "boolean", "default": False}}}),+ Tool(name="revit_create_new_document", description="Create new project", inputSchema={"type": "object", "properties": {"template_path": {"type": "string"}}}),+ Tool(name="revit_export_dwg", description="Export view to DWG", inputSchema={"type": "object", "properties": {"view_id": {"type": "integer"}, "output_path": {"type": "string"}}, "required": ["view_id", "output_path"]}),+ Tool(name="revit_export_ifc", description="Export to IFC", inputSchema={"type": "object", "properties": {"output_path": {"type": "string"}}, "required": ["output_path"]}),+ Tool(name="revit_export_navisworks", description="Export to NWC", inputSchema={"type": "object", "properties": {"output_path": {"type": "string"}}, "required": ["output_path"]}),+ Tool(name="revit_export_image", description="Export view to Image", inputSchema={"type": "object", "properties": {"view_id": {"type": "integer"}, "output_path": {"type": "string"}, "width": {"type": "integer"}, "height": {"type": "integer"}}, "required": ["view_id", "output_path"]}),+ Tool(name="revit_render_3d", description="Render 3D view to image", inputSchema={"type": "object", "properties": {"view_id": {"type": "integer"}, "output_path": {"type": "string"}, "quality": {"type": "string", "enum": ["Draft", "Medium", "High"]}}, "required": ["view_id", "output_path"]}),return tools@@ -632,6 +661,36 @@ async def call_tool(name: str, arguments: Any) -> list[TextContent]:"revit_save_document": ("revit.save_document", {"path": arguments.get("path", "")}),++ # Batch 2: Selection+ "revit_get_selection": ("revit.get_selection", {}),+ "revit_set_selection": ("revit.set_selection", {"element_ids": arguments.get("element_ids")}),++ # Batch 2: Annotation+ "revit_create_text_note": ("revit.create_text_note", {"text": arguments.get("text"), "location": {"x": arguments.get("x"), "y": arguments.get("y"), "z": 0}, "view_id": arguments.get("view_id")}),+ "revit_create_tag": ("revit.create_tag", {"element_id": arguments.get("element_id"), "location": {"x": arguments.get("x"), "y": arguments.get("y"), "z": 0}, "view_id": arguments.get("view_id")}),++ # Batch 2: Structure+ "revit_create_column": ("revit.create_column", {"family_name": arguments.get("family_name"), "type_name": arguments.get("type_name"), "level": arguments.get("level"), "location": {"x": arguments.get("x"), "y": arguments.get("y"), "z": 0}}),+ "revit_create_beam": ("revit.create_beam", {"family_name": arguments.get("family_name"), "type_name": arguments.get("type_name"), "level": arguments.get("level"), "start_point": {"x": arguments.get("start_x"), "y": arguments.get("start_y"), "z": 0}, "end_point": {"x": arguments.get("end_x"), "y": arguments.get("end_y"), "z": 0}}),+ "revit_create_foundation": ("revit.create_foundation", {"family_name": arguments.get("family_name"), "type_name": arguments.get("type_name"), "level": arguments.get("level"), "location": {"x": arguments.get("x"), "y": arguments.get("y"), "z": arguments.get("z", 0)}}),++ # Batch 2: MEP+ "revit_create_duct": ("revit.create_duct", {"level": arguments.get("level"), "start_point": {"x": arguments.get("start_x"), "y": arguments.get("start_y"), "z": arguments.get("z", 10)}, "end_point": {"x": arguments.get("end_x"), "y": arguments.get("end_y"), "z": arguments.get("z", 10)}, "system_type": arguments.get("system_type"), "duct_type": arguments.get("duct_type")}),+ "revit_create_pipe": ("revit.create_pipe", {"level": arguments.get("level"), "start_point": {"x": arguments.get("start_x"), "y": arguments.get("start_y"), "z": arguments.get("z", 0)}, "end_point": {"x": arguments.get("end_x"), "y": arguments.get("end_y"), "z": arguments.get("z", 0)}, "system_type": arguments.get("system_type"), "pipe_type": arguments.get("pipe_type")}),++ # Batch 2: Helpers+ "revit_get_categories": ("revit.get_categories", {}),+ "revit_get_element_type": ("revit.get_element_type", {"category_name": arguments.get("category_name"), "family_name": arguments.get("family_name")}),++ # Batch 2: Remaining Existing+ "revit_close_document": ("revit.close_document", {"save_changes": arguments.get("save_changes", False)}),+ "revit_create_new_document": ("revit.create_new_document", {"template_path": arguments.get("template_path")}),+ "revit_export_dwg": ("revit.export_dwg_by_view", {"view_id": arguments.get("view_id"), "output_path": arguments.get("output_path")}),+ "revit_export_ifc": ("revit.export_ifc_with_settings", {"output_path": arguments.get("output_path")}),+ "revit_export_navisworks": ("revit.export_navisworks", {"output_path": arguments.get("output_path")}),+ "revit_export_image": ("revit.export_image", {"view_id": arguments.get("view_id"), "output_path": arguments.get("output_path"), "width": arguments.get("width"), "height": arguments.get("height")}),+ "revit_render_3d": ("revit.render_3d_view", {"view_id": arguments.get("view_id"), "output_path": arguments.get("output_path"), "quality": arguments.get("quality", "Medium")}),}if name not in tool_mapping:diff --git a/packages/revit-bridge-addin/bin/Release/2024/net48/RevitBridge.dll b/packages/revit-bridge-addin/bin/Release/2024/net48/RevitBridge.dllindex 65a4128..b331281 100644Binary files a/packages/revit-bridge-addin/bin/Release/2024/net48/RevitBridge.dll and b/packages/revit-bridge-addin/bin/Release/2024/net48/RevitBridge.dll differdiff --git a/packages/revit-bridge-addin/bin/Release/2024/net48/RevitBridge.pdb b/packages/revit-bridge-addin/bin/Release/2024/net48/RevitBridge.pdbindex b83c6ed..2bcc422 100644Binary files a/packages/revit-bridge-addin/bin/Release/2024/net48/RevitBridge.pdb and b/packages/revit-bridge-addin/bin/Release/2024/net48/RevitBridge.pdb differdiff --git a/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.AssemblyInfo.cs b/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.AssemblyInfo.csindex 9ae033e..2657a9f 100644--- a/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.AssemblyInfo.cs+++ b/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.AssemblyInfo.cs@@ -13,7 +13,7 @@ using System.Reflection;[assembly: System.Reflection.AssemblyCompanyAttribute("RevitBridge")][assembly: System.Reflection.AssemblyConfigurationAttribute("Release")][assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]-[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8aaafa5a8ed3a0639522ab46b4d28f505747b358")]+[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+aaa0ca0cae7a979e1cb37435cb3becbe7eaaf1f1")][assembly: System.Reflection.AssemblyProductAttribute("RevitBridge")][assembly: System.Reflection.AssemblyTitleAttribute("RevitBridge")][assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]diff --git a/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.AssemblyInfoInputs.cache b/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.AssemblyInfoInputs.cacheindex cf46f7c..419edc5 100644--- a/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.AssemblyInfoInputs.cache+++ b/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.AssemblyInfoInputs.cache@@ -1 +1 @@-88dc057d7d29221ebfc783868eb77b44d09258adcfa78649098344970e4fd455+1714c14dca3dccf2889587661176a27da51cfc7acbe5f10061a209ca7cb2adecdiff --git a/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.dll b/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.dllindex 65a4128..b331281 100644Binary files a/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.dll and b/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.dll differdiff --git a/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.pdb b/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.pdbindex b83c6ed..2bcc422 100644Binary files a/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.pdb and b/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.pdb differdiff --git a/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.sourcelink.json b/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.sourcelink.jsonindex 8b7dd8c..ebd28b3 100644--- a/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.sourcelink.json+++ b/packages/revit-bridge-addin/obj/Release/net48/RevitBridge.sourcelink.json@@ -1 +1 @@-{"documents":{"C:\\Users\\sammo\\OneDrive\\Documenten\\GitHub\\mcp\\*":"https://raw.githubusercontent.com/Sam-AEC/Autodesk-Revit-MCP-Server/8aaafa5a8ed3a0639522ab46b4d28f505747b358/*"}}\ No newline at end of file+{"documents":{"C:\\Users\\sammo\\OneDrive\\Documenten\\GitHub\\mcp\\*":"https://raw.githubusercontent.com/Sam-AEC/Autodesk-Revit-MCP-Server/aaa0ca0cae7a979e1cb37435cb3becbe7eaaf1f1/*"}}\ No newline at end of filediff --git a/packages/revit-bridge-addin/src/Bridge/BridgeCommandFactory.cs b/packages/revit-bridge-addin/src/Bridge/BridgeCommandFactory.csindex 1bd4c0c..0d652a9 100644--- a/packages/revit-bridge-addin/src/Bridge/BridgeCommandFactory.cs+++ b/packages/revit-bridge-addin/src/Bridge/BridgeCommandFactory.cs@@ -4,6 +4,9 @@ using System.Linq;using System.Text.Json;using Autodesk.Revit.DB;using Autodesk.Revit.UI;+using Autodesk.Revit.DB.Structure;+using Autodesk.Revit.DB.Mechanical;+using Autodesk.Revit.DB.Plumbing;namespace RevitBridge.Bridge;@@ -79,6 +82,28 @@ public static class BridgeCommandFactory"revit.export_image" => ExecuteExportImage(app, payload),"revit.render_3d_view" => ExecuteRender3DView(app, payload),+ // Batch 2: Selection+ "revit.get_selection" => ExecuteGetSelection(app),+ "revit.set_selection" => ExecuteSetSelection(app, payload),++ // Batch 2: Annotation+ "revit.create_text_note" => ExecuteCreateTextNote(app, payload),+ "revit.create_dimension" => ExecuteCreateDimension(app, payload),+ "revit.create_tag" => ExecuteCreateTag(app, payload),++ // Batch 2: Structure+ "revit.create_column" => ExecuteCreateColumn(app, payload),+ "revit.create_beam" => ExecuteCreateBeam(app, payload),+ "revit.create_foundation" => ExecuteCreateFoundation(app, payload),++ // Batch 2: MEP+ "revit.create_duct" => ExecuteCreateDuct(app, payload),+ "revit.create_pipe" => ExecuteCreatePipe(app, payload),++ // Batch 2: General Helper+ "revit.get_categories" => ExecuteGetCategories(app),+ "revit.get_element_type" => ExecuteGetElementType(app, payload),+_ => new { status = "error", message = $"Unknown tool: {tool}" }};}@@ -151,7 +176,29 @@ public static class BridgeCommandFactory"revit.export_ifc_with_settings","revit.export_navisworks","revit.export_image",- "revit.render_3d_view"+ "revit.render_3d_view",++ // Batch 2: Selection+ "revit.get_selection",+ "revit.set_selection",++ // Batch 2: Annotation+ "revit.create_text_note",+ "revit.create_dimension",+ "revit.create_tag",++ // Batch 2: Structure+ "revit.create_column",+ "revit.create_beam",+ "revit.create_foundation",++ // Batch 2: MEP+ "revit.create_duct",+ "revit.create_pipe",++ // Batch 2: General Helper+ "revit.get_categories",+ "revit.get_element_type"};}@@ -2406,4 +2453,282 @@ public static class BridgeCommandFactory};}}++ // ==================== BATCH 2: SELECTION & ANNOTATION IMPL ====================++ private static object ExecuteGetSelection(UIApplication app)+ {+ var uidoc = app.ActiveUIDocument;+ if (uidoc == null) throw new InvalidOperationException("No active UIDocument");++ var ids = uidoc.Selection.GetElementIds().Select(id => id.Value).ToList();+ return new { count = ids.Count, element_ids = ids };+ }++ private static object ExecuteSetSelection(UIApplication app, JsonElement payload)+ {+ var uidoc = app.ActiveUIDocument;+ if (uidoc == null) throw new InvalidOperationException("No active UIDocument");++ var ids = payload.GetProperty("element_ids").EnumerateArray()+ .Select(x => new ElementId((long)x.GetInt32()))+ .ToList();++ uidoc.Selection.SetElementIds(ids);+ return new { selected_count = ids.Count };+ }++ private static object ExecuteCreateTextNote(UIApplication app, JsonElement payload)+ {+ var doc = app.ActiveUIDocument?.Document;+ if (doc == null) throw new InvalidOperationException("No active document");++ var text = payload.GetProperty("text").GetString();+ var location = ParseXYZ(payload.GetProperty("location"));+ var viewId = payload.TryGetProperty("view_id", out var v) ? v.GetInt32() : doc.ActiveView.Id.Value;++ using (var trans = new Transaction(doc, "Create Text Note"))+ {+ trans.Start();+ var view = doc.GetElement(new ElementId((long)viewId)) as View;+ var note = TextNote.Create(doc, view.Id, location, text, new ElementId(BuiltInParameter.TEXT_SIZE)); // Using default type logic simplifiction+ trans.Commit();++ return new { text_note_id = note.Id.Value, text = note.Text, view_id = view.Id.Value };+ }+ }++ private static object ExecuteCreateDimension(UIApplication app, JsonElement payload)+ {+ var doc = app.ActiveUIDocument?.Document;+ if (doc == null) throw new InvalidOperationException("No active document");++ // Simplified: In real usage, getting References via API from JSON is hard.+ // Implementation skipped for now or requires selecting elements first?+ // For now, let's implement a placeholder or simple grid-to-grid dimension if possible.+ // Actually, let's defer Dimension creation as it requires Reference objects which are hard to serialize.+ return new { status = "not_implemented", message = "Dimension creation requires complex Reference handling." };+ }++ private static object ExecuteCreateTag(UIApplication app, JsonElement payload)+ {+ var doc = app.ActiveUIDocument?.Document;+ if (doc == null) throw new InvalidOperationException("No active document");++ var elementId = payload.GetProperty("element_id").GetInt32();+ var location = ParseXYZ(payload.GetProperty("location"));+ var viewId = payload.TryGetProperty("view_id", out var v) ? v.GetInt32() : doc.ActiveView.Id.Value;++ using (var trans = new Transaction(doc, "Create Tag"))+ {+ trans.Start();+ var view = doc.GetElement(new ElementId((long)viewId)) as View;+ // IndependentTag.Create replaced NewTag in 2018++ // For Revit 2024 it's Create+ var element = doc.GetElement(new ElementId((long)elementId));+ if (element == null) throw new ArgumentException($"Element {elementId} not found");+ var tag = IndependentTag.Create(doc, view.Id, new Reference(element), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, location);+ trans.Commit();+ return new { tag_id = tag.Id.Value, tagged_element_id = elementId };+ }+ }++ // ==================== BATCH 2: STRUCTURE IMPL ====================++ private static object ExecuteCreateColumn(UIApplication app, JsonElement payload)+ {+ var doc = app.ActiveUIDocument?.Document;+ if (doc == null) throw new InvalidOperationException("No active document");++ var location = ParseXYZ(payload.GetProperty("location"));+ var levelName = payload.GetProperty("level").GetString();+ var familyName = payload.GetProperty("family_name").GetString();+ var typeName = payload.GetProperty("type_name").GetString();++ using (var trans = new Transaction(doc, "Create Structural Column"))+ {+ trans.Start();+ var level = GetLevelByName(doc, levelName);+ var symbol = GetFamilySymbolByName(doc, familyName, typeName);+ if(!symbol.IsActive) { symbol.Activate(); doc.Regenerate(); }++ var instance = doc.Create.NewFamilyInstance(location, symbol, level, StructuralType.Column);+ trans.Commit();++ return new { column_id = instance.Id.Value, family = familyName, type = typeName };+ }+ }++ private static object ExecuteCreateBeam(UIApplication app, JsonElement payload)+ {+ var doc = app.ActiveUIDocument?.Document;+ if (doc == null) throw new InvalidOperationException("No active document");++ var start = ParseXYZ(payload.GetProperty("start_point"));+ var end = ParseXYZ(payload.GetProperty("end_point"));+ var levelName = payload.GetProperty("level").GetString();+ var familyName = payload.GetProperty("family_name").GetString();+ var typeName = payload.GetProperty("type_name").GetString();++ using (var trans = new Transaction(doc, "Create Beam"))+ {+ trans.Start();+ var level = GetLevelByName(doc, levelName);+ var symbol = GetFamilySymbolByName(doc, familyName, typeName);+ if(!symbol.IsActive) { symbol.Activate(); doc.Regenerate(); }++ var line = Line.CreateBound(start, end);+ var instance = doc.Create.NewFamilyInstance(line, symbol, level, StructuralType.Beam);+ trans.Commit();++ return new { beam_id = instance.Id.Value, family = familyName, type = typeName, length = line.Length };+ }+ }++ private static object ExecuteCreateFoundation(UIApplication app, JsonElement payload)+ {+ var doc = app.ActiveUIDocument?.Document;+ if (doc == null) throw new InvalidOperationException("No active document");++ var location = ParseXYZ(payload.GetProperty("location"));+ var levelName = payload.GetProperty("level").GetString();+ var familyName = payload.GetProperty("family_name").GetString();+ var typeName = payload.GetProperty("type_name").GetString();++ using (var trans = new Transaction(doc, "Create Foundation"))+ {+ trans.Start();+ var level = GetLevelByName(doc, levelName);+ var symbol = GetFamilySymbolByName(doc, familyName, typeName);+ if(!symbol.IsActive) { symbol.Activate(); doc.Regenerate(); }++ var instance = doc.Create.NewFamilyInstance(location, symbol, level, StructuralType.Footing);+ trans.Commit();++ return new { foundation_id = instance.Id.Value, family = familyName, type = typeName };+ }+ }++ // ==================== BATCH 2: MEP IMPL ====================++ private static object ExecuteCreateDuct(UIApplication app, JsonElement payload)+ {+ var doc = app.ActiveUIDocument?.Document;+ if (doc == null) throw new InvalidOperationException("No active document");++ var start = ParseXYZ(payload.GetProperty("start_point"));+ var end = ParseXYZ(payload.GetProperty("end_point"));+ var levelName = payload.GetProperty("level").GetString();+ var systemTypeName = payload.TryGetProperty("system_type", out var s) ? s.GetString() : "Supply Air";+ var ductTypeName = payload.TryGetProperty("duct_type", out var d) ? d.GetString() : null; // Default to first available++ using (var trans = new Transaction(doc, "Create Duct"))+ {+ trans.Start();+ var level = GetLevelByName(doc, levelName);++ // Get System Type+ var mechanicalSystemType = new FilteredElementCollector(doc)+ .OfClass(typeof(MEPSystemType))+ .Cast<MEPSystemType>()+ .FirstOrDefault(x => x.Name.Contains(systemTypeName))+ ?? throw new ArgumentException($"MEP System Type '{systemTypeName}' not found");++ // Get Duct Type+ var ductType = new FilteredElementCollector(doc)+ .OfClass(typeof(DuctType))+ .Cast<DuctType>()+ .FirstOrDefault(x => ductTypeName == null || x.Name == ductTypeName); // First available if null++ if (ductType == null) throw new ArgumentException("No Duct Type found");++ var duct = Duct.Create(doc, mechanicalSystemType.Id, ductType.Id, level.Id, start, end);+ trans.Commit();++ return new { duct_id = duct.Id.Value, system_type = mechanicalSystemType.Name, duct_type = ductType.Name };+ }+ }++ private static object ExecuteCreatePipe(UIApplication app, JsonElement payload)+ {+ var doc = app.ActiveUIDocument?.Document;+ if (doc == null) throw new InvalidOperationException("No active document");++ var start = ParseXYZ(payload.GetProperty("start_point"));+ var end = ParseXYZ(payload.GetProperty("end_point"));+ var levelName = payload.GetProperty("level").GetString();+ var systemTypeName = payload.TryGetProperty("system_type", out var s) ? s.GetString() : "Hydronic Supply";+ var pipeTypeName = payload.TryGetProperty("pipe_type", out var p) ? p.GetString() : null;++ using (var trans = new Transaction(doc, "Create Pipe"))+ {+ trans.Start();+ var level = GetLevelByName(doc, levelName);++ var pipingSystemType = new FilteredElementCollector(doc)+ .OfClass(typeof(MEPSystemType))+ .Cast<MEPSystemType>()+ .FirstOrDefault(x => x.Name.Contains(systemTypeName))+ ?? throw new ArgumentException($"Piping System Type '{systemTypeName}' not found");++ var pipeType = new FilteredElementCollector(doc)+ .OfClass(typeof(PipeType))+ .Cast<PipeType>()+ .FirstOrDefault(x => pipeTypeName == null || x.Name == pipeTypeName);++ if (pipeType == null) throw new ArgumentException("No Pipe Type found");++ var pipe = Pipe.Create(doc, pipingSystemType.Id, pipeType.Id, level.Id, start, end);+ trans.Commit();++ return new { pipe_id = pipe.Id.Value, system_type = pipingSystemType.Name, pipe_type = pipeType.Name };+ }+ }++ // ==================== BATCH 2: GENERAL HELPER IMPL ====================++ private static object ExecuteGetCategories(UIApplication app)+ {+ var doc = app.ActiveUIDocument?.Document;+ if (doc == null) throw new InvalidOperationException("No active document");++ var categories = doc.Settings.Categories.Cast<Category>()+ .Where(c => c.CategoryType == CategoryType.Model && c.CanAddSubcategory) // Filter mainly model categories+ .Select(c => c.Name)+ .OrderBy(n => n)+ .ToList();++ return new { categories };+ }++ private static object ExecuteGetElementType(UIApplication app, JsonElement payload)+ {+ var doc = app.ActiveUIDocument?.Document;+ if (doc == null) throw new InvalidOperationException("No active document");++ var categoryName = payload.GetProperty("category_name").GetString();+ var familyName = payload.TryGetProperty("family_name", out var f) ? f.GetString() : null;++ var category = GetCategoryByName(doc, categoryName);+ var collector = new FilteredElementCollector(doc)+ .OfClass(typeof(ElementType))+ .OfCategoryId(category.Id);++ if (!string.IsNullOrEmpty(familyName))+ {+ // Filter by family name if provided+ var types = collector.Cast<ElementType>()+ .Where(x => x.FamilyName == familyName)+ .Select(x => new { family = x.FamilyName, type = x.Name, id = x.Id.Value })+ .ToList();+ return new { types };+ }+ else+ {+ var types = collector.Cast<ElementType>()+ .Select(x => new { family = x.FamilyName, type = x.Name, id = x.Id.Value })+ .ToList();+ return new { types };+ }+ }}