execute_csharp
Run custom C# code inside Revit with direct API access to query or modify the live model, wrapped in an undoable transaction by default.
Instructions
Run any C# code inside Revit with FULL Revit API access (the main tool).
Write a C# script body (statements, optional return value;). Available globals:
uiapp (UIApplication), app (Application), uidoc (UIDocument), doc (active Document),
print(obj) to add output lines, mm(feet)->mm, ft(mm)->feet, id(long)->ElementId.
Namespaces already imported: System, System.Linq, System.Collections.Generic, System.IO, System.Text,
Autodesk.Revit.DB (+ .Architecture .Structure .Mechanical .Plumbing .Electrical), Autodesk.Revit.UI(.Selection).
Revit internal units are feet. With transaction=true (default) the code runs inside one named
transaction that is committed on success and rolled back on any exception; the user can undo it with Ctrl+Z.
Use transaction=false for read-only code or when the code opens/closes/saves documents or manages
its own transactions. Example: return new FilteredElementCollector(doc).OfClass(typeof(Wall)).Count();
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "execute_csharp"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| timeout_s | No | ||
| transaction | No | ||
| transaction_name | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |