Reference for writing bim revit exec snippets. What's pre-injected, what you need to add, and how to discover anything else.
These variables are available in every snippet without any import:
| Variable | Type | Available when |
|---|---|---|
uiApp | Autodesk.Revit.UI.UIApplication | always |
app | Autodesk.Revit.ApplicationServices.Application | always |
doc | Autodesk.Revit.DB.Document | when a document is open |
uiDoc | Autodesk.Revit.UI.UIDocument | when a document is open |
linkedDocs | IEnumerable<Document> | when a document is open |
allDocs | IEnumerable<Document> | when a document is open (active + linked) |
doc and uiDoc are null when no document is open. Scripts that don't need a document can use app and uiApp directly.
| Task | Add to snippet |
|---|---|
| Element collection, filtering, parameters | using Autodesk.Revit.DB; |
| Views, ViewSheet, ViewSchedule | using Autodesk.Revit.DB; |
| PDF export (PDFExportOptions) | using Autodesk.Revit.DB; |
| UI interaction, selection, TaskDialog | using Autodesk.Revit.UI; |
| Application services, language | using Autodesk.Revit.ApplicationServices; |
| Geometry (XYZ, BoundingBoxXYZ, Solid) | using Autodesk.Revit.DB; |
| Built-in categories and parameters | using Autodesk.Revit.DB; — use BuiltInCategory, BuiltInParameter |
| LINQ queries | using System.Linq; |
| Collections (List, Dictionary) | using System.Collections.Generic; |
| JSON serialization | using System.Text.Json; |
| File I/O (Path, Directory, File) | using System.IO; |
| Regex | using System.Text.RegularExpressions; |
The Revit API XML docs are indexed locally. Use these before writing exec code:
# find types matching a keyword
bim revit api search "PDFExportOptions"
# list all members of a type
bim revit api type "Autodesk.Revit.DB.PDFExportOptions"
# full docs for one member
bim revit api describe "M:Autodesk.Revit.DB.Document.Export"
All three commands parse RevitAPI.xml from the locally installed Revit. Results reflect the exact version you're targeting.
Snippets return a string, number, bool, or any JSON-serializable object. Non-serializable Revit objects fall back to .ToString(). For multiple rows use NDJSON:
return string.Join("\n", rows.Select(r => JsonSerializer.Serialize(r)));