Search code examples
revit-apirevitrevitpythonshellpyrevit

Use python to get filter rule information in Revit API


I have started a python script that extracts the filter rule information, but can't find a way to get the information out of the "GetRuleParameters()"

Any help is greatly appreciated. I've seen a lot of information on creating rule filters, but little on extracting the rule information.
Here is an example for filter overrides in a view

Here is where I am at:

pfes = list(FilteredElementCollector(doc).OfClass(ParameterFilterElement).ToElements()) for pfe in pfes:
    rps = pfe.GetRuleParameters()
    for rp in rps:
        print rp.ToString()
        el = doc.GetElement(rp)
        print el

Solution

  • As a starting point it would be more helpful to print the name of the classes rather than to convert the classes to a string. That will not get you everything though. GetRuleParameters will return the elementID of the parameters that are used in the rule; however, the element id of built in parameters is negative. The GetElement function doesn't seem to find parameters if they have a negative element id. I can't find a way to get the built in parameter from the id.

    for pfe in pfes:
        print(pfe.Name)
        rps = pfe.GetRuleParameters()
    
    
        for rp in rps:
    
            el = doc.GetElement(rp)
    
            # this will only work if the parameter used in the
            # filter is not built in
            try:
                print("\t" + el.Name)
            except:
                pass