Close all but active view

Close all but active view

rwebb0418
Contributor Contributor
2,432 Views
2 Replies
Message 1 of 3

Close all but active view

rwebb0418
Contributor
Contributor

Morning everyone,

 

I'm trying to build an addin that opens all the views in the model one by one, does some stuff, and then closes the view.  I can get all the views I want open, but I can't seem to close open views.  

 

Any ideas would be greatly appreciated.

0 Likes
Accepted solutions (1)
2,433 Views
2 Replies
Replies (2)
Message 2 of 3

rwebb0418
Contributor
Contributor
Accepted solution

Nevermind I figured it out.  But for anyone who is interested in my not too pretty solution see below:

 

''TODO: add your code below.

Dim actView As Autodesk.Revit.DB.View = CachedUiApp.ActiveUIDocument.ActiveView
Dim actViewID = actView.Id
Dim views As List(Of ElementFilter) = New List(Of ElementFilter)
views.Add(New ElementClassFilter(GetType(View3D)))
views.Add(New ElementClassFilter(GetType(ViewDrafting)))
views.Add(New ElementClassFilter(GetType(ViewPlan)))
views.Add(New ElementClassFilter(GetType(ViewSection)))

Dim filter As LogicalOrFilter = New LogicalOrFilter(views)

Dim col As FilteredElementCollector
col = New FilteredElementCollector(CachedDoc)
col.WhereElementIsNotElementType()
col.WherePasses(filter)

For Each CurView As Autodesk.Revit.DB.View In col
'MsgBox(CurView.ViewName)
If CurView.IsTemplate = False Then
CachedUiApp.ActiveUIDocument.ActiveView = CurView

End If

Next
Dim openViews = CachedUiApp.ActiveUIDocument.GetOpenUIViews()
For Each openView As Autodesk.Revit.UI.UIView In openViews
If openView.ViewId <> actViewID Then
openView.Close()
End If
Next

0 Likes
Message 3 of 3

jeremytammik
Autodesk
Autodesk

Dear rwebb0418 and anyone else interested in this,

 

Here is a related discussion taking the topic one little step further:

 

http://thebuildingcoder.typepad.com/blog/2012/12/closing-the-active-document.html

 

Cheers, Jeremy.



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