Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Accessing Schedule Category

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
marcart
1983 Views, 5 Replies

Accessing Schedule Category

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

Tags (2)
5 REPLIES 5
Message 2 of 6
marcart
in reply to: marcart

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

Tags (2)
Message 3 of 6
rosalesduquej
in reply to: marcart

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
Message 4 of 6

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

 

Message 5 of 6
jlpgy
in reply to: marcart

public static BuiltInCategory GetUnderlyingCategory(this ViewSchedule viewSchdl)
        {
            return (BuiltInCategory)viewSchdl.Definition.CategoryId.IntegerValue;
        }
单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
Message 6 of 6
rhanzlick
in reply to: jlpgy

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community