Skip to content

woweh/TestEditModeChecker

Repository files navigation

TestEditModeChecker

Revit API 2018 .NET    Revit API 2019 .NET    Revit API 2020 .NET    Revit API 2021 .NET

Platform    License

C# Revit add-in to test if Revit is in Edit Mode.

This Revit add-in shows one technique how to detect if Revit is in some kind of 'Edit Mode'. This work was inspired by the reply of Ahmed Nabil in the Revit API forums:
https://forums.autodesk.com/t5/revit-api-forum/group-edit-event/m-p/9232010/highlight/true#M43668

It works not only for detecting 'Edit Group' mode, but all kinds of edit modes (Edit Assembly, Edit Profile, Edit Stairs, etc...). The technique uses the Revit transaction names to see if a transaction has been started, cancelled or finished.

The add-on might not yet detect all kinds of edit modes.
The author hasn't tested all kinds of edit modes, but the list with transactions to detect edit modes can easily be extended, see constructor of class EditModeChecker.

Also, this has only been tested with English language versions of Revit.
The transaction names probably need translating for non-English versions.

Use Case

Executing Revit API actions from a non-modal (modeless) dialogue, using External Events (> IExternalEventHandler), can produce unexpected results when Revit is in some kind of edit mode.

When starting an action from a non-modal dialogue, the action gets queued and only executed ones Revit is ready to execute the action. When Revit is in some kind of 'edit mode' this can be some time after the action was queued, and the context might have changed significantly, which can render the input invalid.

In that case you might want to stop the user from executing the action in the first place.

References

Sreenshots

Start the "Edit Mode Checker" addin: Start the "Edit Mode Checker" addin

"Edit Group" mode detected: "Edit Group" mode detected

"Edit Group" mode cancelled: "Edit Group" mode cancelled

"Edit Stairs" mode detected: "Edit Stairs" mode detected:

"Edit Stairs" mode cancelled: "Edit Stairs" mode cancelled:

"Edit Profile" mode detected: "Edit Profile" mode detected:

"Edit Profile" mode cancelled: "Edit Profile" mode cancelled:

Author

Wolfgang Weh, Neanex

License

This sample is licensed under the terms of the MIT License.

About

Revit add-in to test if Revit is in 'Edit Mode'

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages