close open views

close open views

russ.green
Advocate Advocate
3,663 Views
5 Replies
Message 1 of 6

close open views

russ.green
Advocate
Advocate

How can I use the API to close open views except the active view?  

 

I can't see how to close a view....

Russ Green
0 Likes
3,664 Views
5 Replies
Replies (5)
Message 2 of 6

russ.green
Advocate
Advocate

or at least just check if a view is open and not active....

Russ Green
0 Likes
Message 3 of 6

ollikat
Collaborator
Collaborator

Hi

 

Not tried or checked in any way the following.

 

You could check what happens if you delete the view from the project with Document.Delete() method, because view also derives from Element.

0 Likes
Message 4 of 6

russ.green
Advocate
Advocate

you can;t delete an open view.  never mind!

Russ Green
0 Likes
Message 5 of 6

Anonymous
Not applicable

 

var pCurrView = pDoc.ActiveView;
pUIDoc.RequestViewChange(pCurrView);                        
var lViews = pUIDoc.GetOpenUIViews();                        
foreach (var pView in lViews)                        
{
    if (pView.ViewId != pCurrView.Id)
        pView.Close();
}

Where pDoc is your Document and pUIDoc is you UIDocument.  Keep in mind, you can access your Document via the UIDocument

Message 6 of 6

Andekan
Participant
Participant

UIDocument.GetOpenUIViews Method Gets a list of all open view windows in the Revit user interface, not only the ones in UIDocument so it may return views from other documents and it may happen that some of them have the same id as the one you want to close so you may end closing mopre than one view

0 Likes