Search code examples
c#revit-api

What is a good alternative to the ViewSheetSet.OrderedViewList property that was added in the 2023 Revit API?


I built a feature in my add-in that automates the filling of dedicated issued date (shared params.) columns on the sheet list schedule. During initialization, I am fetching all the viewsheet sets and adding them to the list box on screen and a sheet set dictionary.

FilteredElementCollector sheetSetColl = new FilteredElementCollector(doc);
 var allSheetSets = sheetSetColl.OfClass(typeof(ViewSheetSet)).ToElements();
 foreach(ViewSheetSet vss in allSheetSets)
 {
   if(!sheetSetDict.ContainsKey(vss.Id))
   {
      if(vss.OrderedViewList.Where(x=>x.ViewType == ViewType.DrawingSheet).Count() != 0)
      {
         sheetSetDict.Add(vss.Id, $"{vss.Name} - {vss.OrderedViewList.Where(x => x.ViewType == ViewType.DrawingSheet).Count()} sheets");
         dpSheetSetCB.Items.Add($"{vss.Name} - {vss.OrderedViewList.Where(x => x.ViewType == ViewType.DrawingSheet).Count()} sheets");
      }
   }
}

The current implementation works in 2023/24, but I realized that the OrderedViewList property of the ViewSheetSet class does not exist for Revit versions before 2023. The only other approaches I can think of are: 1. collecting all views with a set value that isn't null then creating individual lists from unique set IDs during iterating and 2. somehow using ViewSheetSet.Views to extract the Views or IDs then push to a list then using like OrderedViewList. Admittedly, I really want to avoid the first approach. I find it sloppy and time-consuming. The second approach would be great if it actually returned a list or usable object, but it just returns the same ViewSheetSet which brings everything back to square one. How did people list views in Sheet Sets before 2023? Something tells me there's a simple alternative that I'm just blind to after looking at this for so long.


Solution

  • After a good night's sleep and getting a fresh pair of eyes on the problem, I realized that the return type was that of ViewSet instead of ViewSheetSheet, allowing me to add the associated views to a proper list for filtering.

    FilteredElementCollector sheetSetColl = new FilteredElementCollector(doc);
        var allSheetSets = sheetSetColl.OfClass(typeof(ViewSheetSet)).ToElements();
        foreach(ViewSheetSet vss in allSheetSets)
        {
          if(!sheetSetDict.ContainsKey(vss.Id))
          {
            ViewSet vs = vss.Views;
            List<Autodesk.Revit.DB.View> viewList = new List<Autodesk.Revit.DB.View>();
            foreach(Autodesk.Revit.DB.View v in vs)
            {
              viewList.Add(v);
            }
            if(viewList.Where(x => x.ViewType == ViewType.DrawingSheet).Count() != 0)
            {
              sheetSetDict.Add(vss.Id, $"{vss.Name} - {viewList.Where(x => x.ViewType == ViewType.DrawingSheet).Count()} sheets");
              dpSheetSetCB.Items.Add($"{vss.Name} - {viewList.Where(x => x.ViewType == ViewType.DrawingSheet).Count()} sheets");
            }
          }               
        }