FilterByBoolMask using Python

Hi there,
I’m trying to convert the following script to a completely python code for tha sake of practice but I can’t figure it out how to write the python code for FilterByBoolMask. I’d appreciate it if anyone could help me out.

Hi! I believe the simplest way of doing it would be something like this:

inputList = IN[0]
outputList = []

for e in inputList:
   if "L" in e.Name:
      outputList.append(e)

output = outputList

This code would analyse each element of the list and, if the substring “L” is found in the elements’ name string, it would add it to the output list.

The “in” works as the string.contains() and you can find some different ways of achieving this here:

Depending on what you want, you could also want to use string.startswith(“L”) instead:

5 Likes

hi, too late as usual

import sys
import clr
clr.AddReference("RevitAPI")
import Autodesk 
#Import the Class Element
from Autodesk.Revit.DB import Element

Lev=UnwrapElement(IN[0])
search=IN[1]

#Create dictionary
dic={"in_":[l for l in Lev if search in l.Name],"out_":[l for l in Lev if not search in l.Name]}

OUT = dic

cordially
christian.stan

4 Likes

Thanks a lot, that worked fine!

2 Likes

Thank you. This script also worked just perfectly

2 Likes

edit: I forgot that case was not managed here, I don’t know if this is the best solution (I would use string.upper() for the text string and the search string)