How do I determine if the active view is being accessed through a sheet view

How do I determine if the active view is being accessed through a sheet view

Gary_J_Orr
Collaborator Collaborator
4,559 Views
11 Replies
Message 1 of 12

How do I determine if the active view is being accessed through a sheet view

Gary_J_Orr
Collaborator
Collaborator

I'm working my way through the Revit API's (and yes, I've studied the samples in the SDK and done the walk throughs and chased around many, many support pages and so-called help files trying to wrap my head around this convoluted mess).

I'm currently playing with a utility to renumber the views on a sheet. There will be many issues to resolve and things to figure out along the way of course but... I'm already stuck trying to determine one simple and very basic condition:

 

My goal is to determine if the user has a sheet view open. If a sheet view is open but the user has a viewport active, I would like to deactivate the viewport and proceed with the function upon the sheet view itself.

 

ExternalCommandData returns access to the application (from which you can get the active document and the actual application interface) as well as returning the view that is active when the user launched the tool.

 

I can easily determine if the active view is a sheet view or not... as long as the user doesn't have a view on the sheet in active edit mode, in which case the view that gets returned is the view represented by that active viewport (I know using viewport in context of the Revit API for this is incorrect, but it's the best terminology I can come up with, us old CAD guys have terms stuck in our heads from long term association and even the help files use it so I'm gonna run with it).

 

Even if I were to use the properties of that active view to determine if it was placed on a sheet, there is no way to determine if that sheet is open in the editor (a potential hack that I thought of) because the UIDocument..::..GetOpenUIViews Method will return the activated viewport, not the open sheet itself... from the remarks in the help file:

 

Remarks

A sheet view with an activated viewport will return the view associated with the activated viewport, not the sheet view.
 
 
So... how do I determine the actual sheet view that the user has open in the UI in this case?
 
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager

aka (current and past user names)
GaryOrrMBI (MBI Companies 2014-Present), Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Accepted solutions (2)
4,560 Views
11 Replies
Replies (11)
Message 2 of 12

jeremytammik
Autodesk
Autodesk

Dear Gary,

 

Thank you for yet another interesting query.

 

Do you really need to deactivate the viewport to achieve what you want?

 

Why not just go ahead and renumber in any case?

 

Here are the methods and properties that I suggest exploring, but you have probably looked at all of them already: ViewSheet.GetAllViewports, Element.OwnerViewId and Document.ActiveView.

 

I hope this helps.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 12

Gary_J_Orr
Collaborator
Collaborator

Jeremy,

If we used some sort of grid numbering system (or even if we had a truly rigid view numbering system) then I could go ahead and determine the sheet that the active viewport is on and do a few calculations and number the views according to their location on the sheet.

 

Unfortunately, we don't. So, what I need to do is actually deactivate whatever viewport is active to get back to the sheet view itself, then have the user pick the views in the order that they want them to be renumbered.

 

My real problem is the way Revit sends me the data. It does not tell me that I'm on sheetview X with view Y as an active viewport... it, instead, tells me that view Y is my active view. I would get the same result if the user was actually working from view Y when they launched the command.

This is a big difference.

Even if I use the API to determine what sheet owns view Y and then use the API to step through all of the open views, the API will still not tell me that sheetview X is open in the editor as it, also, will return view Y as being an open view, not the containing sheetview X.

In truth, there is another potential conflict...

If the user opens view Y, then opens sheetview X, then activates the viewport to view Y... the API will tell me that the user has view Y open twice with no way to determine that the user actually also has a sheet view open...

 

This seems to me to be a bit of an issue. A difference between what the user is seeing in the UI and what we are being told programmatically by the API.

 

For myself I can take the lazy way out and check to see if the active view is of type "drawingsheet" and pop up a dialog box telling them that they need to be in an active sheet view with no viewports active to run the command, but my goal was to try to determine if, perhaps, the user thought they were in a sheet view (had activated a view, done something, then thought they had deactivated the view, but actually had not) and take steps to help them out.

 

but, again, I'll reiterate:

If a viewport is active on a drawing sheet, there is no way to tell that the drawing sheet itself is open in the editor or that the user is sitting there looking at it...

This seems to me to be a bit of an issue. A difference between what the user is seeing in the UI and what we are being told programmatically by the API.

 

-G

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager

aka (current and past user names)
GaryOrrMBI (MBI Companies 2014-Present), Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Message 4 of 12

jeremytammik
Autodesk
Autodesk

Dear Gary,

 

Thank you for your fantastic explanation.

 

How about the following approach:

 

  • Don't care whether a sheet view or a viewport is open.
  • If the user is in a sheet view, proceed as normal.
  • If the user is in a viewport (and maybe in the containing sheet view, maybe not) switch to the sheet view.
  • If that goes wrong, maybe the user was already in it.

 

Oops, problem, I assume: the viewport can belong to multiple sheets, I assume, so you cannot tell which one to activate.

 

Correct?

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 12

Gary_J_Orr
Collaborator
Collaborator

@Anonymous wrote:

...

Oops, problem, I assume: the viewport can belong to multiple sheets, I assume, so you cannot tell which one to activate.

 

Correct?

 

Cheers,

 

Jeremy


Correct... if the user accidentally has a legend (that may appear on multiple sheets) active how would you determine which sheet that the user is looking at?

 

The information is there... when I'm in a sheet view, regardless of having a viewport activated or not, the titlebar of the window correctly reports the sheet view as being current... so why can't the API tell us as well?

sheet - wo active vp.PNG

 

sheet - w active vp.PNG

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager

aka (current and past user names)
GaryOrrMBI (MBI Companies 2014-Present), Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Message 6 of 12

Anonymous
Not applicable
Accepted solution

you could maybe track ViewSheet and viewport activations to build a journal that describes the path a user took to get to the current view. when a viewport is activated and the previous event was a sheet that owns the viewport it's a good chance that it is the target sheet.

Message 7 of 12

Gary_J_Orr
Collaborator
Collaborator
Thanks for the suggestion Scott, but that's way too much tracking and management for a tool that will be used once or twice per sheet per project. The overhead on the process simply isn't worth the trade off. I may take it far enough to track the users view changes to enable/disable the button, but I may not (just staying with a pop-up telling them that the tool only works in an active sheet view has no overhead at all since it only occurs when the button is pushed)... time will tell

Until the API can tell me what sheet the user is looking at in the UI I'm just going to have to keep it "stupid" and leave it to the user to determine why the tool isn't available.

-G
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager

aka (current and past user names)
GaryOrrMBI (MBI Companies 2014-Present), Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Message 8 of 12

Gary_J_Orr
Collaborator
Collaborator
Accepted solution
Scott,
Thank you for your suggestion. In the end I used part of your suggestion, IE: within my External application class (that installs my tools) I turned on an event Handler for ViewActivated and store the last activated view name. I need this event reactor anyway to enable/disable the button so no loss on overhead.

I'm just skipping the journal and storing the value in a disposable manner.

It turns out that ViewActivated event does not fire when opening a viewport that is on a sheet. This gives me the name of the sheet that the user last switched to. I compare that to the ActiveView returned by my external command class and... viola.
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager

aka (current and past user names)
GaryOrrMBI (MBI Companies 2014-Present), Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Message 9 of 12

joshua.lumley
Advocate
Advocate

 

Use a dialogue box, just ask the user if they are in active viewport.

 

 

0 Likes
Message 10 of 12

joshua.lumley
Advocate
Advocate
            	TaskDialog mainDialog = new TaskDialog("Hello, viewport check!");
                mainDialog.MainInstruction = "Hello, viewport check!";
                mainDialog.MainContent = 
                        "Sadly Revit API doesn't automatically know if the user is in an active viewport. " 
                        + "Please click 'Yes' if your are, or 'No' if your not.";

                mainDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1,
                         "Yes, I am in an active viewport on a sheet.");
                mainDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, 
                                "No, I am just in an ordinary view.");

                mainDialog.CommonButtons = TaskDialogCommonButtons.Close;
                mainDialog.DefaultButton = TaskDialogResult.Close;


                TaskDialogResult tResult = mainDialog.Show();

                bool YesOrNo = true;
 
                if (TaskDialogResult.CommandLink1 == tResult)
                {
						YesOrNo = true;

                }

                else if (TaskDialogResult.CommandLink2 == tResult)
                {
						YesOrNo = false;
                }
                               else{
                return;
                   }	
0 Likes
Message 11 of 12

Anonymous
Not applicable

If you close the view (assuming its not the only view open) - then reopen it,

Revit will have deactived any viewports that where active.

0 Likes
Message 12 of 12

joshua.lumley
Advocate
Advocate

That is quite a clever work around.

0 Likes