List Process, list map in python

#1

Hello,
could you help me with some coding?.
I’m trying to code the same logic as in red circle in python.
Basically I don’t know how to processList intersection def.
Need output like from “list.map” after does.intersect node. Hope it does make sense to you :smiley:

Python warning:
"
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 10, in
File “”, line 5, in ProcessList
File “”, line 5, in <lambda$170>
File “”, line 8, in Intersection
TypeError: Solid is not iterable
"

0 Likes

Linking level depth in a custom node with python
#2

Tomasz,

The ProcessList() method takes care of zipping the two arguments from lists. You don’t have to perform that inside your Intersection() method. Basically change it to:

def Intersection(elA, elB):
    return elA.DoesIntersect(elB) 

Then call it like so:

OUT = ProcessList(Intersection, ducts, walls)

Make sure that the two lists ducts and walls are exactly of the same structure. It works like this:

ducts = [duct1, duct2, duct3]
walls = [wall1, wall2, wall3]

Calling ProcessList(Intersection, ducts, walls) would result in a list [bool, bool, bool] where bool is a true/false if duct1 intersected wall1, duct2 intersected wall2 and duct3 intersected wall3.

It WILL NOT run duct1 against ALL walls, just pair them up. That’s how Zip() works.

1 Like

Python Nodes Basics
#3

That makes sense. Thank you!

0 Likes

#4

As already explained by Konrad your ProcessList and zip() are comparable to how List.Combine works in Dynamo.

If you need List.map you can use a nested for loop:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

solids1 = IN[0]
solids2 = IN[1]
OUT = []

for s1 in solids1:
	sublist = []
	for s2 in solids2:
		sublist.append(s1.DoesIntersect(s2))
	OUT.append(sublist)

List.map, cross-product lacing and this python script will return the same:

If you like map(), this will do the same:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

OUT = map(lambda s1: map(lambda s2: s1.DoesIntersect(s2), IN[0]), IN[1])
3 Likes

#5

That’s perfect. Thank you guys!

0 Likes