Accessing Schedule Category

Accessing Schedule Category

Anonymous
Not applicable
2,637 Views
5 Replies
Message 1 of 6

Accessing Schedule Category

Anonymous
Not applicable

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

0 Likes
Accepted solutions (1)
2,638 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Accepted 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

Message 3 of 6

rosalesduquej
Alumni
Alumni

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



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
0 Likes
Message 4 of 6

Anonymous
Not applicable

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

 

0 Likes
Message 5 of 6

jlpgy
Advocate
Advocate
public static BuiltInCategory GetUnderlyingCategory(this ViewSchedule viewSchdl)
        {
            return (BuiltInCategory)viewSchdl.Definition.CategoryId.IntegerValue;
        }
单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
0 Likes
Message 6 of 6

rhanzlick
Advocate
Advocate

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.

0 Likes