Export parameters list to EXCEL -Convert 2nd level list to string for Excel export

Always get brain damage coming back into Dynamo and Python. :brick:
Using the clockwork node, I extract all the parameter names, categories, parameter groups, parameter type, is visible, parameter element and is instance information for every parameter.

I am trying to convert the associated “Categories” to a string of comma separated values for import to Excel, so the columns remain aligned - otherwise on export the categories break the columnar formatting. I only want to convert the 2nd level list where there are multiple items and return the string as a single itme in the list so as not to break the excel export. VBA’d in excel in 15 minutes to merge, but want this in Dynamo/PY - and I know its possible

The array to string converts all the elements from the upper and lower lists into one big string. No way to have it just convert the @l2 which is what I am after.

attempted a python but cannot get the Names of the Categories:

# Load the Python Standard and DesignScript Libraries
import clr
import sys
from Autodesk.DesignScript.Geometry import *
import Autodesk
from Autodesk.Revit.DB import *

# The inputs to this node will be stored as a list in the IN variables.
myList = UnwrapElement(IN)

for i in  myLists:
    j=','.join(Category.Name(x) + ',' for x in UnwrapElement(i))
OUT = j         ##Dumb output for now- want to sub the string for the list
                ##of the sublist in Mylist[*][HERE]
                ##so Mylist[*][0]= join(every element in Mylist[*][*]

DYN attached - areas in RED is the issue.

Would like to understand how to replace a 2nd level list of elements with a single item list of the concatenated string… to export to get this:

Export_parameters.dyn (52.1 KB)


The .Join function of Python’s string class is a good place to start; it will take a list of strings and convert it to a single string the initial string as the separator. Something like this (don’t have Python available as I finish recovering from COVID, so you may need to edit):

listOfStrings = [“Thing A”, “Thing B”, “Thing 1”, “Thing 2”]
joinedStrings = “, “.join(listOfStrings”
OUT = joinedStrings
1 Like

I want to "roll up " at this 2nd level…
getting the names of the classes in python has proven to be challenging as well. Tried variations on the syntax- and unwrapelements() but no joy : (

Assuming those are strings, unwrapping isn’t the issue - Dynamo’s Python integration will treat the two data types the same. The only time you need to unwrap is when you convert from a Dynamo interpretation of a .net object to a native .net object (ie: a Dynamo reference to a Revit wall to a native Revit Wall). Dynamo > Python should happen automatically for standard data types.

Since you have a list of lists you’ll want to add a for loop or utilize list comprehension to achieve the result.

This runs fine in an online Python environment, so assuming you have a list structure which matches this you should be all set. If it’s a different list structure you’ll have to alter the setup accordingly.

myListOfLists = [ ["Thing 1", "Thing 2", "Thing 3"], ["Thing A", "Thing B", "Thing C"] ]
#For Loop Example
forLoopResults = []
for myList in myListOfLists:
    forLoopResults.append( ", ".join(myList) )

#List Comprehension Example
listComprehensionResults = [ ", ".join(myList) for myList in myListOfLists ]

#return both results to the Dynamo environment
OUT = forLoopResults, listComprehensionResults
1 Like

The array to string converts all the elements from the upper and lower lists into one big string. No way to have it just convert the @l2 which is what I am after.

Assuming I’ve understood correctly, then String.Join will do what you’re after:


there is a small error

try this

import sys
import clr
import Autodesk
from Autodesk.Revit.DB import *

myList_with_sublst = UnwrapElement(IN[0])
OUT = []

for sublst in  myList_with_sublst:
    j =','.join(x.Category.Name  for x in sublst)

@Hamish , nope, that is the problem. I want to maintain the list structure @L1 but turn ead @L2 sublist into a string for export of parameters : )