Set value for Schedule Filter

Hello everyone, I’m trying to set value for schedule filter. I found that Revit API has a SetValue method for schedule filter so I used it but I got this warning: AttributeError: ‘ScheduleFilter’ object has no attribute ‘SetValue’. Maybe I have a mistake somewhere. Please take a look at the images below and give me some advices. Thank you.


the IN[0] is really RevitAPI object?

@newshunhk they’re all schedule filters that I take from a Dynamo Node. I don’t know whether they’re a Revit API objects or not. I’ve been learning Revit API for a couple weeks now. Can you help me?

can you show more the left hand side?

@newshunhk Here’s the whole Dynamo graph. Please take a look.
Set Value For Schedule Filter.dyn (39.8 KB)

I think what @newshunhk is saying is that Dynamo ScheduleFilters may not unwrap properly into Revit objects. You would probably be better off doing everything in Python or everything in Dynamo (at least as far as filters). Is there a reason you’re assigning the filter value in Python instead of continuing with nodes?

@Nick_Boyts yes, there’re two reasons that I want to do it in Python. The first reason is I can’t find a SetValue node for Schedule Filters in Dynamo. The second is because I’ve been learning Revit API for a couple weeks so I want to give my self a chance to practice with it

If you’re wanting to set the value of an existing filter then I think you’re right, there is no node to do that. But there is a node, ScheduleFilter.ByFieldTypeAndValue that creates the filter all at once.

Learning the API is always a good idea. Just as a tip, make sure you’re still using the API where it makes sense and also not getting burned out if you’re constantly running into issues with a specific case. The idea is to get familiar, get some experience, and learn. Don’t worry about getting everything right.

Now for your actual scenario here, I would recommend doing the whole thing in python if you’re wanting to use the API, especially to learn. Start with an input schedule (or better yet, a FilteredElementCollector to find all schedules for you), get the schedule definition, the schedule filter, and then modify the filter value.

1 Like

@Nick_Boyts Thank you for your help. I’ll try it and will tell you the result.

Hi,

A tip using Reflection to convert a Revit.Schedules.ScheduleFilter to Revit.DB.ScheduleFilter
(unfortunately UnwrapElement() don’t work in this case)

import sys
import clr
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("System.Reflection")
from System.Reflection import BindingFlags

def convert_to_DB(e):
    invokeObj = clr.GetClrType(e.GetType()).InvokeMember('InternalScheduleFilter', 
                                                        BindingFlags.InvokeMethod | \
                                                        BindingFlags.GetProperty | \
                                                        BindingFlags.Instance | \
                                                        BindingFlags.Public | \
                                                        BindingFlags.NonPublic, 
                                                        None, 
                                                        e, 
                                                        None)
    return invokeObj

lstscheduleFilter = IN[0]

lstScheduleFilter = [convert_to_DB(x) for x in lstscheduleFilter]

OUT = lstScheduleFilter
2 Likes

@c.poupin Thanks a lot. I’ll definitely try it.