Description
Dynamo uses non-types multi dimensional arrays, and this may seem as an advantage at the beginning but sometimes lists just don’t match. I’ve written this custom node to tackle these situations.
The custom node provides multiple options for making lists match, you can borrow elements from the other list or add some fixed value.
I used python to make this custom node, the solution is relatively simple and python is easy choice for this. The basic ideea is to recursively iterate through each list and detect where something is missing
To assemble the custom node just paste the python code in a python script block. Then add the inputs and outputs just like in the image to the left.
Solution
import re 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); """ L1 = {a,b,c,{d,e,f}} L2 = {{1,1}, {2,2}, 3, {4, {5,5}, 6}} L1Transformes = {{a,a}, {b,b}, c, {d, {e,e}, f}} """ log = []; lastItemL1 = False; lastItemL2 = False; lastItem = False; def matchElementForList(_element, _list): global lastItem; retList = []; if isIterable(_list): for _item in _list: if isIterable(_item): retList.append(matchElementForList(_element, _item)); else: lastItem = _item; retList.append(_element); else: retList = _element; return retList; def displayList(l): ll = ""; if isIterable(l): for item in l: ll = ll + str(item); return ll; else: return str(l); logcOUNT = 0; def operate(List1, List2, fillCondition, fixedFillValue): global lastItemL1; global lastItemL2; global logcOUNT global lastItem log.append("data1: " + str(logcOUNT) + ":|>"+ str(List1)); log.append("data2: " +str(logcOUNT) +str(":|>")+str(List2)); log.append("lastItemL1: " + str(":|>") + str(lastItemL1)); log.append("lastItemL2: " + str(":|>") + str(lastItemL2)); logcOUNT = logcOUNT + 1 if not isIterable(List1) and not isIterable(List2): lastItemL1 = List1; lastItemL2 = List2; """ input = (a, b); output = [a, b]; """ return [List1, List2] elif not isIterable(List1): lastItemL1 = List1; """ input = (a, [1,2,3]]; output = [[a,a,a], [1,2,3]] """ ret = [matchElementForList(List1, List2), List2] lastItemL2 = lastItem return ret elif not isIterable(List2): lastItemL2 = List2; """ input = ([a,b,c], 1) output = ([a,b,c], [1,1,1]) """ ret = [List1 , matchElementForList(List2, List1)] lastItemL1 = lastItem return ret; else: """ fillCondition = 0: input = ([a,b,c,d], [1,2,3]) output = ([a,b,c,d], [1,2,3,None]) """ """ fillCondition = 1: input = ([a,b,c,d], [1,2,3]) output = ([a,b,c,d], [1,2,3,d]) """ """ fillCondition = 2: input = ([a,b,c,d], [1,2,3]) output = ([a,b,c,d], [1,2,3,fixedValue]) """ """ fillCondition = 3: input = ([a,b,c,d], [1,2,3]) output = ([a,b,c,d], [1,2,3,3]) """ minlen = min(len(List1), len(List2)) retBranchLeft = []; retBranchRight = []; for idx in range(minlen): result = operate(List1[idx], List2[idx], fillCondition, fixedFillValue); retBranchLeft.append(result[0]); retBranchRight.append(result[1]); for idx in range(minlen, minlen + (len(List1) - minlen), 1): if fillCondition not in [1,2,3]: match = None; elif fillCondition == 1: match = List1[idx]; elif fillCondition == 2: match = fixedFillValue elif fillCondition == 3: match = lastItemL2; result = operate(List1[idx], match, fillCondition, fixedFillValue); retBranchLeft.append(result[0]); retBranchRight.append(result[1]); for idx in range(minlen, minlen + (len(List2) - minlen), 1): if fillCondition not in [1,2, 3]: match = None; elif fillCondition == 1: match = List2[idx]; elif fillCondition == 2: match = fixedFillValue elif fillCondition == 3: match = lastItemL1; result = operate(match, List2[idx], fillCondition, fixedFillValue); retBranchLeft.append(result[0]); retBranchRight.append(result[1]); return [retBranchLeft, retBranchRight]; FillGapsWithNone = IN[2]; FillGapsWithNextListItems = IN[3]; FillGapsWithFixedValue = IN[4]; FillGapsWithLastItem = IN[5] FixedValue = IN[6]; fillc = 0; if FillGapsWithNone == True: fillc = 0; if FillGapsWithNextListItems == True: fillc = 1; if FillGapsWithFixedValue == True: fillc = 2; if FillGapsWithLastItem == True: fillc = 3; #Assign your output to the OUT variable. OUT = operate(IN[0], IN[1], fillc, FixedValue), log