Delete unused views (Views not placed on sheets)

SanjivKapila
Participant
Participant

Delete unused views (Views not placed on sheets)

SanjivKapila
Participant
Participant
I'm trying to delete unused views with following conditions: 1. View should not have any dependent views 2. Views which can be placed on multiple sheets (eg Legends) should not be deleted if they are placed on at least one sheet. 3. Unused ViewSchedules should also get deleted Attached code is an unsuccessful attempt at achieving this.
Reply
Accepted solutions (1)
15,712 Views
11 Replies
Replies (11)

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @SanjivKapila ,

try using the below link

https://thebuildingcoder.typepad.com/blog/2017/11/purge-and-detecting-an-empty-view.html#2 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes

SanjivKapila
Participant
Participant

Hi Naveen

Thanks for your reply, but I'm not trying to detect empty views, rather I'm trying to delete unused views without harming any sheet. Any view placed on the sheet should not be deleted. The issues I'm facing are: dependent views get deleted if we delete the parent view, i'm using the CanBePlacedOnSheet method: but it deletes legends and other views which can be placed on multiple sheets..

Is there a way to collect all the views on the sheets and subtract it from the main collection of views and delete the resulting collection by applying some conditions..

0 Likes

jeremytammik
Autodesk
Autodesk
Accepted solution

Yes, you can easily achieve that.

  

Look at GetAllPlacedViews:

  

https://www.revitapidocs.com/2020/816db942-4e9c-7278-7f59-53048becc46a.htm

  

Create a list of all placed view by asking all sheets for their placed views.

  

Any view that is not contained in that list is unplaced.

  



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

0 Likes

SanjivKapila
Participant
Participant

Not Sure Why, but i end up deleting all the legend views even though some are placed on the sheets.

0 Likes

Sean_Page
Collaborator
Collaborator

Check the ViewType property and make sure it does not equal Legend.

 

if(view.ViewType != ViewType.Legend)
{
    Add to list
}

You can also check to see if the BIP VIEWPORT_DETAIL_NUMBER and/or VIEWPORT_SHEET_NUMBER are empty.

 

Also you may want to look for View Templates as well.

if(!view.IsTemplate)
{
    Add to list
}

And a big one I ran into is making sure  not to delete the Patent of any dependent views because typically they are not on sheets.

 

if(view.GetPrimaryViewId == ElementId.InvalidElementId)
{
    Add to list
}
else
{
    Remove from list
}
Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect

Jerry.Vanek.SG
Observer
Observer

There's a great plug-in from Ideate called SheetManager, which lets you isolate unplaced views. 

 

image.png

tylerVD3L4
Enthusiast
Enthusiast

Can you share the solution and where I would input the code in Revit?

0 Likes

tylerVD3L4
Enthusiast
Enthusiast

I found a tool that does this. Use pyrevit plugin, and use the Wipe tool

0 Likes

trevor.ritchieC68GZ
Explorer
Explorer

Can you just use the "Browser Organisation":

trevorritchieC68GZ_0-1675723042301.png

 

trevorritchieC68GZ_0-1675723107663.png

 

mark.perryS7U4L
Explorer
Explorer

Does it smartly hide parent views that aren't on sheets?

0 Likes

archcad2019
Community Visitor
Community Visitor

how i can use this option in revit ? please provide me with steps

0 Likes