Zeros as function work result

After working out the loop, I get zeros for each element that does not meet the conditions described in the function. What do I need to edit in the function to not get zeros in after the loop?
I need a list of correct elements without zeros.


def FilterSystemPipe(_pipe, system_name):
	if _pipe.MEPSystem != None:
		if _pipe.MEPSystem.Name.startswith(system_name):
			return _pipe if _pipe != None or _pipe != 0 or _pipe != "" else 'RandomText'
	else: errorlist.append("The pipe hasn't system Id=" + _pipe.Id.ToString())

cold_pipes, errorlist = [],[]

pipes = UnwrapElement(IN[0])
#pipes = FilteredElementCollector(doc).OfClass(Pipe).ToElements())

for pipe in pipes:
	cold_pipes.append(FilterSystemPipe(pipe, 'В1'))
OUT = cold_pipes, errorlist

Hi @Kungur,

I don’t fully understand your question. But see if this points you in the right direction.

def FilterSystemPipe(_pipes, system_name):
    cold_pipes, errorlist = [],[]
    for _pipe in _pipes:
        if _pipe.MEPSystem != None:
            if _pipe.MEPSystem.Name.startswith(system_name):
                if _pipe != None or _pipe != 0 or _pipe != "":
                else: cold_pipes.append("RandomText")
            else: errorlist.append("The pipe hasn't system Id=" + _pipe.Id.ToString())
    return cold_pipes, errorlist

toList = lambda x : x if hasattr(x, '__iter__') else [x]

pipes = toList(UnwrapElement(IN[0]))

OUT = FilterSystemPipe(pipes,"B1")
1 Like

Thank you, I will try to explain in detail.

I need to create lists of pipes that will be sorted by pipe systems. For example, DomesticHotWater, DomesticColdWater and etc.

I’m trying to create a function to filter pipes. My problem is that I get a list of elements that fulfill the condition “The system name starts with …” and elements that do not match this condition in the form of Null.
For example,

List1 [pipe, pipe, pipe]
List2 = [Null, pipe, Null, Null, pipe and etc…]
I need to get List1.

I tried to remove Null with this code. I think it’s superfluous because it doesn’t help.

return _pipe if _pipe != None or _pipe != 0 or _pipe != "" else 'RandomText'

Why not use a FilterByBoolMask node instead of Python?

Hi @Kungur

  1. filter your collector to get only pipe instances
  2. then use the collector and apply a Linq extension method or Predicate to re-filter it (or other method)


import clr
import sys
import System
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

#import Revit API
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import specify namespace
from Autodesk.Revit.DB.Plumbing import *

#import net library
from System import Array
from System.Collections.Generic import List, IList, Dictionary

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument


collector = FilteredElementCollector(doc).OfClass(Pipe).WhereElementIsNotElementType()
pipesB1 = collector.Where(lambda x : x.MEPSystem.Name.startswith("B1")).ToList()
pipesCH1 = collector.Where(lambda x : x.MEPSystem.Name.startswith("CH1")).ToList()

OUT = pipesB1, pipesCH1