Activate/Deactivate View on Sheet

Hello Dynamo friends :slight_smile:

I want to know if i can make a view on a sheet active or inactive with Dynamo.
RevitAPIDocs says that i can get and set the active view, is the “set” function what i want?
ActiveView Property (revitapidocs.com)

Here is an example where i need to set a view to inactive:
The userinterface wants the user to select views on a sheet, but it’s not possible because a view is active.

There are some significant technical limitations on what you’re after. I’ll start with a few brief statements of fact, simplified to a great degree, for educational purposes.

  1. Any change to a Revit model (making or modifying an element) requires a transaction. In just about any application, transactions are difficult things to manage effectively and safely; Revit is no exception.
  2. Revit can only take one set of input commands at a time; this is to prevent corruption of the model, loss of work, and worksharing issues (imagine having two mice plugged into the same computer operating in the same Revit session at once; think of allthe problems that could cause - this prevents those problems).
  3. Any change in the Revit user interface requires that no transaction is active, again this is to prevent corruption, loss of work, and worksharing issues.
  4. Dynamo for Revit is an ‘in process’ integration, meaning that in order to run it ‘takes attention away’ from the host application.

Because it’s ‘in process’ (#4) and because transactions are difficult to manage when you have no idea what users will be doing (#1), Dynamo initiates a Revit transaction when you hit ‘run’. This let’s Revit know it’s about to receive some instructions on stuff to do.

So we have an open transaction, which means that changes to the UI are blocked (#3). In fact the very documentation for the API method you posted indicate this is the case (note the emphasis on the first bullet is added):

Remarks

This property is applicable to the currently active document only. Returns a null reference ( Nothing in Visual Basic) if this document doesn’t represent the active document.

The active view can only be changed when:

  • There is no open transaction.
  • IsModifiable is false.
  • IsReadOnly is false.
  • ViewActivating, ViewActivated, and any pre-action of events (such as DocumentSaving or DocumentClosingevents) are not being handled.

So the question becomes, how can you get around this? Could a separate application be launched to allow the update perhaps? Maybe, but because Revit will only allow one set of input at a time (#2) this isn’t likely to work well, or at least not in a stable manor if it does work out at all. This leaves you with one last option: force the view to deactivate prior to the transaction starting, but Dynamo can’t do that as once you start the run the transaction is already underway.

This leaves you with one last option; prior to initiating the ‘select viewport’ aspect of your code, check if the active view is a sheet view; If so cancel the rest of the graph to prevent issues, and tell the user to ‘open a sheet and ensure that all viewports are deactivated prior to running this graph’. It’s not a great solution, but most (all?) full add-ins have some feature like this built into them (ie: try using an add-in while in the middle of editing a stair sketch).

Hope this helps!

Hello Jacob,

Thank you for your explanation!

The script already works if i want it to when a sheet is active and a view is selected.
Adding the ability to also work if a view is active would have been a nice upgrade.

As you can see, when the Data-Shapes UI is running i am still able to set views inactive and active, and this is exactly what i would like to do with dynamo.

ezgif-2-5072e1e68c

I think i have to leave the idea that everything that is possible with the mouse in revit should also be possible with dynamo!?

As soon i hit the “select views” button i will get into the selection command, which i think is a standard revit command. when I´m in there and a view is active i can´t do anything. A workaround is i can hit “cancel”, inactivate the view and hit “select views” again. Not very user friendly.

So another workaround would be to let dynamo cancel this revit selection command:
image
But that again will not work because i can`t do anything with dynamo while this is running.

It seems that there is only one way to achieve what i want.
Giving the user the information that he has to deactivate the view himself before he can continue.

Now i found some threads about this topic and i tested the method “RequestViewChange()”.

ezgif-7-140cc7be11

This works and opens the selected view.
I tried if this also works for a sheet, but it doesnt. So it does’t help for my problem.

But in the information to this method i found something interesting:

Remarks

This method requests to change the active view by posting a message asynchronously. Unlike setting the ActiveView property, this will not make the change in active view immediately. Instead the request will be posted to occur when control returns to Revit from the API context. This method is permitted to change the active view from the Idling event or an ExternalEvent callback.

So there should be a “set active view” method and it should even work immideatly!

1 Like

Made a mistake, RequestViewChange() is also working with sheets:

ezgif-7-853998c5a7

But also this doesnt help me when a view on a sheet is activated.