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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
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 |