Retrieve all parameters that can be assigned to a multi-category Schedule programmatically

Retrieve all parameters that can be assigned to a multi-category Schedule programmatically

Anonymous
Not applicable
809 Views
2 Replies
Message 1 of 3

Retrieve all parameters that can be assigned to a multi-category Schedule programmatically

Anonymous
Not applicable
 //Code to retrieve all multi-Category-Schedules
FilteredElementCollector elementCollector = new FilteredElementCollector(Common.ProjectDocument);

List<ViewSchedule> multiCategorySchedules = elementCollector.OfClass(typeof(ViewSchedule))
                 .ToElements()
                 .Cast<ViewSchedule>()
                 .ToList()
                 .Where(x => x.Definition.CategoryId.IntegerValue == -1)
                 .ToList<ViewSchedule>();
//The loop is not needed in this case because the project only has
//one multi-category - schedule, but out of habit I left it
foreach ( ViewSchedule schedule in multiCategorySchedules)
{
//Retireve all the unique fields for one schedule
  Dictionary<ElementId, string> availableParameters = new 
  Dictionary<ElementId, string>();

  ScheduleDefinition def = schedule.Definition;
  foreach(SchedulableField p in def.GetSchedulableFields())
  {
   if (!availableParameters.ContainsKey(parameterId))
      {
        availableParameters.Add(parameterId, name);
      }
    }

}

Hello,

Currently I am working on code that is supposed to retrieve all available parameters for a multi-category schedule. As shown the in the screenshot below ,I have four different fields available (Multiple Categories, Room, Space, Project Information) from which I can select parameters.

The code that I attached is able to retrieve all of them, however, it also retrieves about 200 more parameters that I am not able to assign to this schedule. I did check for unique element ids, however, it only eliminated a few extra parameters. Could somebody take a look at my code and help my understand if I am missing something or if the parameters that I don't seem to be able to find are hidden somewhere in Revit.

Thanks a lot in advance!

0 Likes
810 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

Does the IsSchedulableField predicate help filter out the unwanted ones?

 

https://www.revitapidocs.com/2021.1/f08c6d5b-600d-8770-1e02-31d4c31641f0.htm

 

The description says, Checks whether a non-calculated/non-combined field is eligible to be included in this schedule.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

Anonymous
Not applicable

Hi Jeremy,

I also added these 5 fields to my code and still don't get the exact result:

 

if (!availableParameters.ContainsKey(parameterId)
&&( p.FieldType == ScheduleFieldType.ProjectInfo
|| p.FieldType == ScheduleFieldType.Room
|| p.FieldType == ScheduleFieldType.Space
|| p.FieldType == ScheduleFieldType.ElementType || p.FieldType == ScheduleFieldType.Instance))
{
availableParameters.Add(parameterId, name);
}

 

However, after experimenting with the "FieldType", I noticed that the additional parameters are all Instance parameters. When I filtered by every FieldType that I used above except for ScheduleFieldType.Instance, I didn't have any additional parameters, but was missing  all the  Instances. 

My suspicion is that the additional parameters are Family-Instance parameters, but I am going to do a little bit more research on that.

Thanks for the hint!

0 Likes