Code behaving differently in two python nodes

So this has got me perplexed…

I collected all the Wall Instances in a list and than I got their respective Wall Types. Then I wanted to sort this list in the same Python Node to get a list of uniqe values of Wall Types that are present in the model but it didnt work. I tried the “if not in” method and the sort() function but neither seems to work.

If I use the “unique values” Dynamo Node OR perform the sorting in another python node than it works. Can anyone explain??

“GET WALL TYPES NODE”
Category = ListBuiltInCategory
category.Add(BuiltInCategory.OST_Walls)
filter = ElementMulticategoryFilter(category)
collector = FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType().ToElements()

types = []
data = []

for item in collector:
	types.append(item.WallType)
# Code unterhalb dieser Linie platzieren
for i in types:
	if i not in data:
		data.append(i)

OUT = data

“IF NOT IN” NODE

data = []
# Code unterhalb dieser Linie platzieren
for i in IN[0]:
	if i not in data:
		data.append(i)
# Weisen Sie Ihre Ausgabe der OUT-Variablen zu.
OUT = data

“SET METHOD” Node

OUT = set(IN[0])

@c.poupin Do you know why is this happening?

if we expose the list to the Revit API (method UnwrapElement() ) we get the same result as if we were in the same Python node, it is the Dynamo wrapper that makes the difference

a workaround with a set on a collection of ElementId

Note
The Python set () operator use hash of each object

Example with a comparison between the hashes of the Elements and their Ids

5 Likes

@c.poupin Thank you for the explanation.

1 Like