Hi,
I am trying to find the category for an existing schedule. I am filtering elements by ViewSchedule type but I don't find any property that returns the category for that schedule (there is one called "category" but is always null).
Is there any way to find it? Seams an easy thing to do, maybe I am understanding something wrong?
Thanks for your help.
Marc
Solved! Go to Solution.
Solved by marcart. Go to Solution.
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
Hi Marc,
Your Solution seems correct to me, you are accessing the neccesary data to obtain the categories names, I will say that if its working for you, why not use that solution. Great job!
Cheers
Hello,
1- While creating a Beam Schedule I want to add a "Beam Location Mark" and Slab location mark in terms of grid Similar to Column Schedule.
I want to locate Beam in form of B1-E1 0r B1-B5. Similarly for Slab Location Mark in form of B1-D5. Can anyone help me out?
2- I also want cross Sectional Dimensions (length x width) field in Beam and Column Schedule. Please Help me out.
Thanks, Amit
public static BuiltInCategory GetUnderlyingCategory(this ViewSchedule viewSchdl)
{
return (BuiltInCategory)viewSchdl.Definition.CategoryId.IntegerValue;
}
I really wanted this solution to work as it seems like the intended method, but it kept returning null for me. Since ViewSchedules are also a View in Revit, you can run a filtered element collector with a View.Id filter to get the elements visible in your schedule. from these elements, you can just get the category:
Category scheduleCategory = new FilteredElementCollector(doc, viewSchedule.Id).Select(el => el.Category).First();
definitely a weird workaround, but it does seem to work.