Collecting views from model

Collecting views from model

MOR75669
Contributor Contributor
53 Views
1 Reply
Message 1 of 2

Collecting views from model

MOR75669
Contributor
Contributor

Hello,

 

I am a little bit confused and was hoping someone could help me please.

I found the following code in the forum to collect all the views, and testing in on the "Arch Link Model" project that comes with revit 2023 (in samples folder).

var allViews = new FilteredElementCollector(doc).OfClass(typeof(View)).WhereElementIsNotElementType().ToElements();
var elementsToDelete = new List<Element>();
foreach (View view in allViews)
{   switch ( view.ViewType)
    {case ViewType.FloorPlan:
     case ViewType.CeilingPlan:
     case ViewType.Elevation:
     case ViewType.ThreeD:
     case ViewType.DraftingView:
     case ViewType.AreaPlan:
     case ViewType.Section:
     case ViewType.Detail:
     case ViewType.Rendering:
     case ViewType.Walkthrough:
     elementsToDelete.Add(view);
     break;
     default:
     case ViewType.Report:
     case ViewType.ProjectBrowser:
     case ViewType.SystemBrowser:
     case ViewType.CostReport:
     case ViewType.LoadsReport:
     case ViewType.PresureLossReport:
     case ViewType.SystemsAnalysisReport:
     case ViewType.Internal:
     break;
    }
}
var totalViews = elementsToDelete.Count.ToString();
TaskDialog.Show("Revit", totalViews);

I have created a schedule and the total number of views i get from the script is different to the schedule  

Revit API test.jpg

 

0 Likes
54 Views
1 Reply
Reply (1)
Message 2 of 2

MOR75669
Contributor
Contributor

Silly me 😁

I was listing the View Templates too, sorted it 

.........

foreach (View view in allViews)
{ if (!view.IsTemplate){   
switch ( view.ViewType)........

0 Likes