Namespace → using directive table, pre-injected globals, and version-specific quirks for writing bim revit exec snippets across Revit 2022–2026.
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.
using directiveThese namespaces are available in all supported Revit versions (2022–2026) unless noted otherwise.
| Namespace | Add to snippet | What 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.
| Revit version | Access element ID as integer |
|---|---|
| 2022, 2023 | element.Id.IntegerValue |
| 2024, 2025, 2026 | element.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.
| Revit version | Notes |
|---|---|
| 2022–2024 | doc.ActiveProjectLocation.GetProjectPosition(...).Latitude works |
| 2025, 2026 | Latitude and Longitude removed from ProjectPosition. Use doc.SiteLocation.Latitude / doc.SiteLocation.Longitude instead. |
| Context | Notes |
|---|---|
| Family documents | doc.FamilyCreate.NewExtrusion() available in all 2022–2026 versions |
| Project documents | Geometry creation methods (NewExtrusion, NewSweep, etc.) are family-document only and throw InvalidOperationException in a project context. Use DirectShape for project-level geometry instead. |
| Pattern | Notes |
|---|---|
| Auto-transaction (default) | bim revit exec wraps the snippet in a Transaction automatically. Safe for write operations in all 2022–2026 versions. |
--no-transaction | Required when: setting uidoc.ActiveView, calling doc.Regenerate() standalone, or managing your own nested transactions. |
uidoc.ActiveView = view | Throws InvalidOperationException inside the auto-transaction. Fix: pass --no-transaction to the exec call. |
| Revit version | Notes |
|---|---|
| 2022–2026 | doc.Export(folder, IList<ElementId> viewIds, PDFExportOptions) available. PDFExportOptions.Combine = false = one PDF per view. Use --no-transaction for export calls. |
| Revit | .NET target | TCP port | Notes |
|---|---|---|---|
| 2022 | net48 (.NET Framework 4.8) | 14700 | Use ElementId.IntegerValue |
| 2023 | net48 | 14701 | Use ElementId.IntegerValue |
| 2024 | net48 | 14702 | Use ElementId.Value; IntegerValue removed |
| 2025 | net8.0-windows | 14703 | ProjectPosition.Latitude/Longitude removed |
| 2026 | net8.0-windows | 14704 |
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.
# 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"