Always get brain damage coming back into Dynamo and Python.
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
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
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[*][*]
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):
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
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:
import sys
import clr
clr.AddReference('RevitAPI')
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)
OUT.append(j)