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: 

The field and filter type cannot be used to filter this ScheduleDefinition

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
1069 Views, 3 Replies

The field and filter type cannot be used to filter this ScheduleDefinition

Hello Everyone,

 

Does anyone encounterd such exception ? I try to copy schedules and give the copies additional filter, but as soon as i start copy filters i get this exception. I chcecked every possible source of problems and found nothing. As much as i know, i get this error while trying to apply correct filter on correct ScheduleField. Does anyone have an idea what could possibly be wrong ? Many thanks.

 

Code

(I tried copying filters using GetFilters() and SetFilters() of course, but it failed)

                        ViewSchedule targetViewSchedule = ViewSchedule.CreateSchedule(document, sourceViewSchedule.Definition.CategoryId, sourceViewSchedule.Definition.AreaSchemeId);


                        IList<ScheduleFieldId> sourceFieldOrder = sourceViewSchedule.Definition.GetFieldOrder();
                        foreach (var fieldId in sourceFieldOrder)
                        {
                            ScheduleField sourceField = sourceViewSchedule.Definition.GetField(fieldId);
                            SchedulableField sourceSchedulableField = sourceField.GetSchedulableField();
                            ScheduleField targetField = targetViewSchedule.Definition.AddField(sourceSchedulableField);
                            targetField.ColumnHeading = sourceField.ColumnHeading;
                            targetField.IsHidden = sourceField.IsHidden;
                        }
                        IList<ScheduleSortGroupField> sourceScheduleSortGroupField = sourceViewSchedule.Definition.GetSortGroupFields();
                        if (sourceScheduleSortGroupField != null)
                        {
                            targetViewSchedule.Definition.SetSortGroupFields(sourceScheduleSortGroupField);
                        }


for (int i = 0; i < sourceFilterCount; i++) { ScheduleFilter filter = sourceViewSchedule.Definition.GetFilter(i); ScheduleField sourceFieldToBeFiltered = sourceViewSchedule.Definition.GetField(filter.FieldId); ScheduleFieldId targetFieldToBeFilteredId = null; for (int j = 0; j < targetFieldCount; j++) { ScheduleField targetField = targetViewSchedule.Definition.GetField(j); if (targetField.ColumnHeading == sourceFieldToBeFiltered.ColumnHeading) { targetFieldToBeFilteredId = targetField.FieldId; } } if (filter.IsDoubleValue) { double value = filter.GetDoubleValue(); ScheduleFilter newFilter = new ScheduleFilter(targetFieldToBeFilteredId, filter.FilterType, value); targetViewSchedule.Definition.AddFilter(filter); } else if (filter.IsElementIdValue) { ElementId value = filter.GetElementIdValue(); ScheduleFilter newFilter = new ScheduleFilter(targetFieldToBeFilteredId, filter.FilterType, value); targetViewSchedule.Definition.AddFilter(filter); } else if (filter.IsStringValue) { string value = filter.GetStringValue(); ScheduleFilter newFilter = new ScheduleFilter(targetFieldToBeFilteredId, filter.FilterType, value); targetViewSchedule.Definition.AddFilter(filter); } else if (filter.IsIntegerValue) { int value = filter.GetIntegerValue(); ScheduleFilter newFilter = new ScheduleFilter(targetFieldToBeFilteredId, filter.FilterType, value); targetViewSchedule.Definition.AddFilter(filter); } }

 

3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

I'm having the same error when trying to filter my rooms by level.

 

string levelName = "1st floor";

 

ViewSchedule schedule = ViewSchedule.CreateSchedule(_doc, new ElementId(BuiltInCategory.OST_Rooms), ElementId.InvalidElementId);

 

// ... skipping code that adds some other fields and groups by department ... 

 

ScheduleField level = schedule.Definition.AddField(def.GetSchedulableFields().FirstOrDefault<SchedulableField>(sf => sf.GetName(_doc) == "Level"));

 

if (level.ParameterId == new ElementId(BuiltInParameter.ROOM_LEVEL_ID))
{
       ScheduleFilter filter = new ScheduleFilter(level.FieldId, ScheduleFilterType.Contains, levelName);
       schedule.Definition.AddFilter(filter);              <-------breaks here

}

 

Did you find a solution to this?

Message 3 of 4
Anonymous
in reply to: Anonymous

I'm guessing that because you have just built the schedule from scratch the API isn't yet properly aware of its new fields when you attempt to use one as a filter and throws an exception. I'd try either calling a Document.Regenerate() or commiting the transaction and starting a new one before adding the filter.

 

Just to be safe, I'd also add a break; immediately after targetFieldToBeFilteredId = targetField.FieldId; and then also check for null value of targetFieldToBeFilteredId just before if (filter.IsDoubleValue)

 

That said, there is an easier way to copy a schedule. 🙂

 

Use something like:

 

ViewSchedule newSchedule = dbDoc.GetElement(existingSched.Duplicate(ViewDuplicateOption.Duplicate)) as ViewSchedule;

This one line can replace pretty much all of the code you posted. It should preserve any existing sorting, grouping, filters, column sizing and any other formatting, which is quite handy. The schedule created using this method should be ready for applying the new additional filters without any extra work.

 

 

 

 

Message 4 of 4
Ryan
in reply to: Anonymous

Hi all,

 

Very new to programing the API, but coming along.

 

Im using similar code in a external command,

 

 

ViewSchedule newSchedule = dbDoc.GetElement(existingSched.Duplicate(ViewDuplicateOption.Duplicate)) as ViewSchedule;

 

But i cant figure out how to grab a filter thats already in the duplicated scheadule, and change its value.

 

This is what i have so far..

 

            using (Transaction trans = new Transaction(doc, "ViewDuplicate"))
            {
                trans.Start();
                foreach (ViewSchedule vw in views)
                {
                    // Duplicate the existing schedule
                    ViewSchedule newView = doc.GetElement(vw.Duplicate(ViewDuplicateOption.Duplicate)) as ViewSchedule;
                    // Assign the desired name
                    if (null != newView)
                        newView.ViewName = "MyViewName";

 

 

Thanks!

 

 

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