I found a way to know the Schedule category, but I think it should be an easier way. If you know, please let me know.
Method 1 didn't work for me and I thought to be the right one.
FilteredElementCollector collector = new FilteredElementCollector(_doc)
.OfClass(typeof(ViewSchedule));
foreach (ViewSchedule s in collector)
{
if (s.Category != null)
{
string category = s.Category.Name;
}
}
the variable category was never populated because s.Category was always null.
Method 2 worked but seamed to long for a simple data like a category.
List<MySchedule> listSched = new List<MySchedule>();
FilteredElementCollector collector = new FilteredElementCollector(_doc)
.OfClass(typeof(ViewSchedule));
Categories categories = _doc.Settings.Categories;
foreach (ViewSchedule s in collector)
{
ScheduleDefinition definition = s.Definition;
ElementId catSched = s.Definition.CategoryId;
MySchedule mySchedule = new MySchedule();
if (!s.IsTitleblockRevisionSchedule)
{
foreach (Category cat in categories)
{
if (cat.Id == catSched)
{
mySchedule.Category = cat.Name;
break;
}
mySchedule.Category = "<Multi-Category>";
}
mySchedule.Name = s.ViewName;
listSched.Add(mySchedule);
}
}
This worked for me but I wonder if someone knows an easier way.
Thanks!!
Marc