Revit API namespaces & using directives

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 "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.

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)));