Skip to content

[Context] Read the API context and the UI application from the Revit 2027 internals - #130

Merged
Nice3point merged 3 commits into
developfrom
context/revit-2027-internal-members
Oct 18, 2026
Merged

Nice3point merged 3 commits into
developfrom
context/revit-2027-internal-members

Conversation

@Nice3point

@Nice3point Nice3point commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Summary of the Pull Request

What is this about:

RevitContext reads the API context and the UI application from internal members of the Revit 2027 API.

Description:

What changed

  • On Revit 2027, IsRevitInApiMode calls the internal Application.IsInAPIContext() through an UnsafeAccessor.
  • On earlier versions, IsRevitInApiMode calls the native APICallDepthManager functions of RevitDBAPI through function pointers. It no longer invokes them through reflection or loads APIUIAPI.
  • On Revit 2027, UiApplication is the session UIApplication from the internal UIApplication.Instance. Earlier versions construct it from Application.
  • The runtime project allows unsafe code for the function-pointer calls.

Where to look

  • APIUIAPI and RevitDBAPI both declare APICallDepthManager.singletonfactory and isRevitInAPIMode as P/Invoke into the same native functions, in Revit 2023 to 2027.
  • UIApplication.Instance returns UIApplication::getInstance(). The public constructor resolves the same native object through getUIApplication(getMFCApp(...)) and rejects a call while a DB application is active.
  • Revit keeps the DialogBoxShowing handlers in a static map keyed by the native pointer, so BeginDialogSuppressionScope subscribes and unsubscribes through any wrapper of the session.

How verified

  • Build: Release.R20, Release.R24, Release.R26, Release.R27, zero errors.
  • Revit tests: 73 passed, zero failed, on Revit 2027 and 2024. Revit 2024 covers the function-pointer path on .NET Framework.
  • New tests: IsRevitInApiMode returns false from a thread pool thread, and on the Revit thread for work queued through the dispatcher outside the API context. The second test fails for an implementation that compares threads.
  • Revit 2027, measured with BenchmarkDotNet in a Revit process without the user interface:
IsRevitInApiMode implementation Mean Allocated
Reflection 61.96 ns 112 B
Function pointers 36.34 ns —
Application.IsInAPIContext() 27.43 ns —
  • Revit 2026: the installed patch runs on .NET 10, and the committed test project targets .NET 8 for that version. The tests passed only with a temporary .NET 10 target override, before the UiApplication change.

Quality Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

@Nice3point
Nice3point marked this pull request as ready for review October 15, 2026 20:20
Copilot AI balanced review requested due to automatic review settings October 15, 2026 20:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Nice3point
Nice3point merged commit 9ef9250 into develop Oct 18, 2026
1 check passed
@Nice3point
Nice3point deleted the context/revit-2027-internal-members branch October 18, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants