Revit API reference

Namespace → using directive table, pre-injected globals, and version-specific quirks for writing bim revit exec snippets across Revit 2022–2026.

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.

Namespace → using directive

These namespaces are available in all supported Revit versions (2022–2026) unless noted otherwise.

NamespaceAdd to snippetWhat it covers
Autodesk.Revit.DB using Autodesk.Revit.DB; Elements, documents, parameters, geometry (XYZ, BoundingBoxXYZ, Solid), filtering (FilteredElementCollector), views, sheets, transactions, PDF export (PDFExportOptions), built-in categories and parameters (BuiltInCategory, BuiltInParameter)
Autodesk.Revit.UI using Autodesk.Revit.UI; UI interaction, task dialogs, selection, UIDocument, UIApplication, ribbon and external commands
Autodesk.Revit.ApplicationServices using Autodesk.Revit.ApplicationServices; Application services, language settings, version info, product type
Autodesk.Revit.Creation using Autodesk.Revit.Creation; Factory methods for creating elements: Document.Create, Application.Create. Required for NewExtrusion(), NewFamilyInstance() and similar creation APIs — family-document only for geometry creation methods.
System.Linq using System.Linq; LINQ queries — pre-injected, available without explicit import
System.Collections.Generic using System.Collections.Generic; List<T>, Dictionary<K,V>, etc. — pre-injected
System.IO using System.IO; File, Path, Directory — for export scripts writing to disk
System.Text.Json using System.Text.Json; JSON serialization for structured return values
System.Text.RegularExpressions using System.Text.RegularExpressions; Regex for name/parameter filtering

Use bim revit api search <term> to look up which namespace any type lives in against your locally installed Revit version.

Version-specific quirks (2022–2026)

ElementId — integer value access

Revit versionAccess element ID as integer
2022, 2023element.Id.IntegerValue
2024, 2025, 2026element.Id.Value (returns long; IntegerValue removed in 2024)

For snippets that must run on both old and new versions: use bim revit api describe "P:Autodesk.Revit.DB.ElementId.Value" to check availability against your target.

ProjectPosition — latitude/longitude

Revit versionNotes
2022–2024doc.ActiveProjectLocation.GetProjectPosition(...).Latitude works
2025, 2026Latitude and Longitude removed from ProjectPosition. Use doc.SiteLocation.Latitude / doc.SiteLocation.Longitude instead.

Autodesk.Revit.Creation — NewExtrusion and geometry creation

ContextNotes
Family documentsdoc.FamilyCreate.NewExtrusion() available in all 2022–2026 versions
Project documentsGeometry creation methods (NewExtrusion, NewSweep, etc.) are family-document only and throw InvalidOperationException in a project context. Use DirectShape for project-level geometry instead.

Transaction mode

PatternNotes
Auto-transaction (default)bim revit exec wraps the snippet in a Transaction automatically. Safe for write operations in all 2022–2026 versions.
--no-transactionRequired when: setting uidoc.ActiveView, calling doc.Regenerate() standalone, or managing your own nested transactions.
uidoc.ActiveView = viewThrows InvalidOperationException inside the auto-transaction. Fix: pass --no-transaction to the exec call.

PDF export

Revit versionNotes
2022–2026doc.Export(folder, IList<ElementId> viewIds, PDFExportOptions) available. PDFExportOptions.Combine = false = one PDF per view. Use --no-transaction for export calls.

.NET target and TCP port by Revit year

Revit.NET targetTCP portNotes
2022net48 (.NET Framework 4.8)14700Use ElementId.IntegerValue
2023net4814701Use ElementId.IntegerValue
2024net4814702Use ElementId.Value; IntegerValue removed
2025net8.0-windows14703ProjectPosition.Latitude/Longitude removed
2026net8.0-windows14704

A .NET target mismatch causes the TCP bridge to fail silently at startup. Run bim revit status --detailed to check the installed add-in version against your Revit year.

Diagnosing version issues

# check add-in version, port state, and installation
bim revit status --detailed

# verify a type or member exists for your installed version
bim revit api search "ProjectPosition"
bim revit api type "Autodesk.Revit.DB.ProjectPosition"
bim revit api describe "P:Autodesk.Revit.DB.ElementId.Value"