The category of the ScheduleSheetInstance is: OST_ScheduleGraphics
The category of the ViewSchedule is: OST_Schedules
They should work but in this instance I would usually use a class filter, typically I use class filter unless they can't be used. When you use a class filter it inherently distinguishes between types and instances:
FamilySymbol/FamilyInstance
WallType/Wall etc.
Regarding (1) something of this nature would work:
Public Function Obj_220207a(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result
Dim app = commandData.Application
Dim uidoc = commandData.Application.ActiveUIDocument
Dim IntDoc = uidoc.Document
Dim VS As ViewSchedule = TryCast(IntDoc.ActiveView, ViewSchedule)
If VS Is Nothing Then Return Result.Cancelled Else
Dim FEC As New FilteredElementCollector(IntDoc)
Dim ECF As New ElementClassFilter(GetType(ScheduleSheetInstance))
Dim Els As List(Of ScheduleSheetInstance) = FEC.WherePasses(ECF).ToElements _
.Cast(Of ScheduleSheetInstance) _
.Where(Function(x) x.ScheduleId = VS.Id).ToList
Dim SheetIds As List(Of ElementId) = Els.Select(Function(x) x.OwnerViewId).Distinct.ToList
For i = 0 To SheetIds.Count - 1
Dim VSht As ViewSheet = IntDoc.GetElement(SheetIds(i))
Debug.WriteLine(VSht.SheetNumber & " - " & VSht.Name)
Next
Return Result.Succeeded
End Function
public Result Obj_220207a(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication app = commandData.Application;
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document IntDoc = uidoc.Document;
ViewSchedule VS = IntDoc.ActiveView as ViewSchedule;
if (VS == null)
return Result.Cancelled;
FilteredElementCollector FEC = new FilteredElementCollector(IntDoc);
ElementClassFilter ECF = new ElementClassFilter(typeof(ScheduleSheetInstance));
List<ScheduleSheetInstance> Els = FEC.WherePasses(ECF).ToElements().Cast<ScheduleSheetInstance>().Where(x => x.ScheduleId == VS.Id).ToList();
List<ElementId> SheetIds = Els.Select(x => x.OwnerViewId).Distinct().ToList();
for (int i = 0; i <= SheetIds.Count - 1; i++)
{
ViewSheet VSht = (ViewSheet) IntDoc.GetElement(SheetIds[i]);
Debug.WriteLine(VSht.SheetNumber + " - " + VSht.Name);
}
return Result.Succeeded;
}