Detecting Modify Mode aka Edit Mode

Detecting Modify Mode aka Edit Mode

Anonymous
Not applicable
3,090 Views
17 Replies
Message 1 of 18

Detecting Modify Mode aka Edit Mode

Anonymous
Not applicable

I have encountered some issues while using the API if the user has left Revit in Modify Mode aka Edit Mode when trying some operations.  For example, if I click on a Roof (graphically) then edit the Comment on the Roof and hit Apply, Revit leaves the app in Edit Mode with the Modify|Roof ribbon highlighted green.  I would like to be able to either be notifified with an event when the user enters or exits this mode, or be able to check a property.

0 Likes
3,091 Views
17 Replies
Replies (17)
Message 2 of 18

arnostlobel
Alumni
Alumni
Jasonleejackson:

And you need such an event because you want to disable or re-enable your modeless palette upon Revit entering and leaving an edit mode, respectively?

Thank you
Arnošt Löbel
0 Likes
Message 3 of 18

Anonymous
Not applicable

I just want to detect it so I don't allow the user to take the action my code does. It would be most convenient for me to get an event, because then I can disable a button in my add-in, but if I can only access a property I might then warn the user that they cannot proceed by checking that property when they click the button.

0 Likes
Message 4 of 18

arnostlobel
Alumni
Alumni
So, basically, you are confirming what I asked, right?
Arnošt Löbel
0 Likes
Message 5 of 18

Anonymous
Not applicable

I don't know if something is getting lost here; I am not real clear why you are going around with me. Am I missing something? I don't know what a modeless palette is. I feel like I described fairly succinctly what I actually am trying to do. Are you aware of a property or event that can be used to determine if Revit is in Modify mode?

0 Likes
Message 6 of 18

Anonymous
Not applicable

So I just went to do some research about what a modeless palette is. Apparently Autodesk uses that term for the properties editor. I don't want to do anything, at all, with the modeless palette them. Totally unconcerned with it. Don't care. I have an add-on that is on a ribbon. I want to disable a button there if Modify mode is happening as described in my original question, else enable that button. If I cannot do this with something like an event then checking a property would be great.

 

Besides the point of what I want to do with the information, this seems like an incredibly straight forward question? How does one find out if Revit is in Modify mode from the .Net API?

0 Likes
Message 7 of 18

Anonymous
Not applicable

the Application.IsQuiescent property is what you need. look it up on the api reference

 

0 Likes
Message 8 of 18

arnostlobel
Alumni
Alumni

jasonleejackson:

 

It was a perfectly reasonable question you asked. I simply wanted to find out more. I am sorry I was not clear enough about it. Your added details explain it fine why you need the event. However, in your case the event should not be necessary, because all buttons related to external commands should be disabled automatically when Revit is in an edit mode. It the the same with external commands in the Add-ins menu. There are (should be) all disabled when in edit mode, for all API is disabled in edit modes - meaning Revit never calls out from an edit more (or while the end-user is editing and/or have an open transaction). If your ribbon button is not disabled while Revit is in an edit mode, we (Revit R&D) need to to look into it. 

 

I asked about modeless palettes (or any modeless dialog) because it is probably the only legitimate reason for someone needing the event you mentioned. Unless I am forgetting something, that is.

 

IsQuiescent cannot be used, technically, because it should not be called from outside the main thread. And if an an API user is actually calling on the main thread, then the answer to is IsQuiescent is going to be always False, for Revit would be busy with executing the very same application that is calling IsQuiescent.

 

Arnošt Löbel
0 Likes
Message 9 of 18

Anonymous
Not applicable
I am creating a custom ribbon with custom buttons in WPF, which then launches a custom modal which eventually asks Revit to execute API code for me using an IExternalEventHandler implementation. If a user has left the app in the Modify (Quescient) state then my callbacks are extremely slow. I will raise an event and then a few minutes later Revit will callback, and then wait as long to answer the next event. I had hope to be able to respond to an idle event of some sort. Reading through various blog posts it looks like IsQuiscent is dangerous to call outside of context because it is part of the Revit API. It also looks like the idle example in the SDK is not the path either from what I have read over on the Building Coder blog. It looks like I may just be stuck.
0 Likes
Message 10 of 18

arnostlobel
Alumni
Alumni

I am sorry, but I must ask again. What do you means by "I am creating a custom ribbon with custom buttons in WPF." Where is the Ribbon? Is it at the Ribbon bar in Revit? If so, how do you create the custom ribbon there and how do you add your commands there? Is it bia the Revit API? If your ribbon is NOT at the Revit ribbon bar, where is it?

 

I am asking because if you need to execute an external command it means you are communicating from an outside thread (like, basically, from a modeless dialog which is what I ask about first at the beginning.)

 

Thanks

Arnošt Löbel
0 Likes
Message 11 of 18

Wolfgang.B.Weh
Enthusiast
Enthusiast

I'm having exactly the same use casea non-modal dialogue using an IExternalEventHandler.

To detect edit mode I'm checking the transaction names in the DocumentChanged event, as suggested by Ahmed Nabil in this post:
https://forums.autodesk.com/t5/revit-api-forum/group-edit-event/m-p/9232010/highlight/true#M43668

I've created an example project to show how it works:

https://github.com/woweh/TestEditModeChecker

This works for me and my use-case.

You might have to extend the solution to cater for non-English versions of Revit or any edit mode transactions which I might have missed.

 

It would be nice if Autodesk could add events to the ControlledApplication which get triggered when some edit mode starts or ends.

 

Thanks

 

Wolfgang

0 Likes
Message 12 of 18

RPTHOMAS108
Mentor
Mentor

Although this thread is old it isn't as old as the property RibbonButton.IsEnabled since then (or around the same time) RibbonButton.IsEnabledByContext was added also.

 

Does this second property not work i.e. even for modeless dialogues where you could query a static variable of the RibbonButton you've added to show your modeless dialogue or some other button on the Revit Ribbon prior to raising the external event?

 

Would be interested to know the answer to this.

 

 

 

 

0 Likes
Message 13 of 18

Wolfgang.B.Weh
Enthusiast
Enthusiast

Not sure if we talk about the same thing.

In my case, I'm having a non-modal WinForm (but the same would apply for a WPF form) where functionality should be disabled when the user enters some "Edit Mode" in Revit.

I'm not talking about buttons in the Revit ribbon.

 

When searching I find three similar questions/discussions:

Naing Oo suggest in his post to monitor the Revit ribbon to see if Revit is in "Assembly Edit Mode". I guess this technique can also be extended to check for all kinds of edit modes.

 

Can you give me some more details about how RibbonButton.IsEnabled or RibbonButton.IsEnabledByContext can be used to solve this problem?

 

Regards

 

Wolfgang

 

0 Likes
Message 14 of 18

RPTHOMAS108
Mentor
Mentor

I've not tested but in theory if you have access to a static variable containing any ribbon item either one created by your Add-in or one found to exist by looking through Revit Ribbon during OnStartUp. Then you could look at it's IsEnabledByContext at anytime. 

 

i.e. within the event handler for your button on the modeless window/form you first review the RibbonItem.IsEnabledByContext stored on a static field containing RibbonItem or the UIApplication. If one Add-in button is disabled this way they likely all are.

 

There may be issues surrounding holding onto a static version of UIApplication, although it's state is not as changeable as UIDocument or other DB level API objects. If that is an issue then idling event provides a fresh UIApplication. From UIApplication you can iterate the ribbon items to see if any Ribbon Add-in item has this property set to true/false.

 

I'm kind of following the logic that if you reflect the state of any Revit Revit Ribbon button in your modeless one by inspecting such then you achieve the same. Often even modeless forms/windows require some button that your add-in knows about on the Revit ribbon to show them for the first time.

0 Likes
Message 15 of 18

zhuliyi0
Enthusiast
Enthusiast

Tested, seems the property .IsEnabledByContext and .Enabled are both always true, when the UI shows it grayed out.

 

I've tested the adWindow.dll route mentioned in another post, partly works, but not perfect.

 

https://forums.autodesk.com/t5/revit-api-forum/determine-when-revit-api-is-not-available/m-p/8429631...

0 Likes
Message 16 of 18

RPTHOMAS108
Mentor
Mentor

Yes unfortunately I noticed that. I also noticed that the idling event didn't fire when in 'edit' mode and this gave me another (non AdWindows) idea which seems to work well:

 

1) Subscribe to idling event which reports current system ticks to a variable

2) Start a timer on a separate thread (interval 250) to check the current system ticks against the last idle time from (1)

3) Within timer elapsed event raise new class wide event on modeless window with event args containing boolean .Enabled:

3a) If 0.5 seconds or more has passed since last idle set EventArgs.Enabled to false.

3b) If less than 0,5 seconds has passed since last idle set EventArgs.Enabled to true.

4) Subroutine on modeless windows handles event. Dispatcher for window instance is invoked to update it's UI.

 

It seems quite reliable for short test periods and has the added benefit of working also for when modal dialogues are displayed i.e. it is in effect an AntiIdlingEvent or a BusyingEvent perhaps a ActivingEvent...(actual name to follow).

 

The attached solution is in VB.Net and has some VB specific language features regarding events but I'm sure it could be adapted for C#.

 

 

 

 

  

Message 17 of 18

Wolfgang.B.Weh
Enthusiast
Enthusiast

Looks good. Well done!

Thanks for your efforts.

0 Likes
Message 18 of 18

jeremy_tammik
Alumni
Alumni

This other discussion seems closely related and may provide some additional useful ideas:

 

https://forums.autodesk.com/t5/revit-api-forum/determine-when-revit-api-is-not-available/m-p/7926155

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes