Recursivity to handle multi-dimensional arrays — Digitteck
Recursivity to handle multi-dimensional arrays
dotnet·4 February 2018·1 min read

Recursivity to handle multi-dimensional arrays

Description

Dynamo handles lacing on its own (provided that the python script is within a custom node), however sometimes you may have to handle multi-dimensional arrays by yourself. The solution is simple — use recursivity. Basically you iterate through each element in the list and if the item is a list, then apply the iterate function to that item, if not then apply the custom function.

Solution

python
import re
### isIterable function determines if the object is an array or not
def isIterable(unit):
	t1 = t2 = False;
	if(isinstance(unit, (tuple, set, list, dict))):
		t1 = True;
	if(hasattr(unit, "__iter__")):
		iterstr = str(unit.__iter__());
		if(re.search("System.Array", iterstr)):
			t2 = True;
	return (t1 or t2);
### iterating over the list (if it's a list) or apply function
def iterateAndDo(elements, myFunction):
	if(isIterable(elements)):
		returnList = [];
		for element in elements:
			returnList.append(iterateAndDo(element, myFunction));
		return returnList;
	else:
		return myFunction(elements);
### our custom function
def Log(input):
    #do something here
    return;

OUT = iterateAndDo(IN[0], Log)

Tags

DynamoPythonListsRecursivityVisual Programming
digitteck

© 2026 Digitteck