Revit API namespaces & using directives

install bim-cli · windows · per-user · no admin
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command 'iwr -useb https://bimcli.com/install.ps1?src=site -OutFile $env:TEMP\bim-install.ps1; powershell -NoProfile -ExecutionPolicy Bypass -File $env:TEMP\bim-install.ps1'

Reference for writing bim revit exec snippets. What's pre-injected, what you need to add, and how to discover anything else.

Pre-injected globals

These variables are available in every snippet without any import:

VariableTypeAvailable when
uiAppAutodesk.Revit.UI.UIApplicationalways
appAutodesk.Revit.ApplicationServices.Applicationalways
docAutodesk.Revit.DB.Documentwhen a document is open
uiDocAutodesk.Revit.UI.UIDocumentwhen a document is open
linkedDocsIEnumerable<Document>when a document is open
allDocsIEnumerable<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.

Common namespaces by task

TaskAdd to snippet
Element collection, filtering, parametersusing Autodesk.Revit.DB;
Views, ViewSheet, ViewScheduleusing Autodesk.Revit.DB;
PDF export (PDFExportOptions)using Autodesk.Revit.DB;
UI interaction, selection, TaskDialogusing Autodesk.Revit.UI;
Application services, languageusing Autodesk.Revit.ApplicationServices;
Geometry (XYZ, BoundingBoxXYZ, Solid)using Autodesk.Revit.DB;
Built-in categories and parametersusing Autodesk.Revit.DB; — use BuiltInCategory, BuiltInParameter
LINQ queriesusing System.Linq;
Collections (List, Dictionary)using System.Collections.Generic;
JSON serializationusing System.Text.Json;
File I/O (Path, Directory, File)using System.IO;
Regexusing System.Text.RegularExpressions;

Discover any type or member

The Revit API XML docs are indexed locally. Use these before writing exec code:

# find types matching a keyword
bim revit api search --query PDFExportOptions

# list all members of a type
bim revit api type --name Autodesk.Revit.DB.PDFExportOptions

# only the overloads of one member
bim revit api type --name Autodesk.Revit.DB.Document --members Export

All three commands parse RevitAPI.xml from the locally installed Revit. Results reflect the exact version you're targeting.

Return values from exec

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)));
related Revit API reference: namespaces and version quirks Revit version-specific API quirks Revit CLI: run C# and export sheets -- bim-revit Headless Revit — Run Revit Unattended from the CLI
install bim-cli · windows · per-user · no admin
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command 'iwr -useb https://bimcli.com/install.ps1?src=site -OutFile $env:TEMP\bim-install.ps1; powershell -NoProfile -ExecutionPolicy Bypass -File $env:TEMP\bim-install.ps1'

Then ask your assistant to run bim describe --json. See what the installer does.