Does anyone know of an elegant way to get the Element.GetParameterValueByName to work with elements that are organized into nested lists?
See my example below:
My desired result is shown in red and should yield all 20s in a list format that matches the given element format.
A python script from a thread earlier this month would work:
LIST : MATCH LEVELS
a dynamoPython script, visit the website for more details
__author__ = 'Kenzo Bird - email@example.com'
__dynamoforum__ = 'Kennyb6'
__version__ = '1.0'
Script to match structure of one list to another.
IN must be completely flattened prior to this script.
Empty lists in either inputs may give unwanted results.
def recCount(_lists, c):
# Count all elements in the structure list (IN)
for _list in _lists:
if isinstance(_list, list):
c = recCount(_list, c)
c += 1
def recMatch(_list, _matches, _out, c):
Recreate the value list (IN) according to the structure list (IN)
_list = entire value list
_matches = the current list level of the structure list
_out = value list matching the structure list to be passed on
c = count to be used as the current index of the value list
for _match in _matches:
if isinstance(_match, list): # if list, recurse another level deeper
outTemp, c = recMatch(_list, _match, , c)
c += 1
return _out, c
mList = IN # List of values, flattened to single level
toMatch = IN # Original structured list
outList =  # Need blank list to be appended, will be new value list
c = 0
mC = 0
# Checks that both lists are equal value to prevent invalid index errors
if len(mList) == recCount(toMatch, c):
OUT = recMatch(mList, toMatch, outList, mC)
in0Len = "IN length = " + str(recCount(mList, c))
in1Len = "IN length = " + str(recCount(toMatch, c))
OUT = ["List lengths do not match.", in0Len, in1Len]
Note that you should flatten the input to GetParameterValueByName first.
Appreciated, this did the trick @kennyb6 !
You probably could have used Lacing or Levels to make this hope. Without another node.
Levels doesn’t work in this case, as far as I tested. If you can make it work, please show us.
Although no, I was not able to get levels to work, if you List.Map it I think would be a better option.