Python Skript having parameter Name and Value at the same spot

Hello guys,
im trying to get a list of parameter from my select elements nodes. My problem is i would like the list to look like they are on the same “level”, for example “Lining Type: null” next list “Velocity Pressure: 0.0 PA” and so on, but somehow i cant get the value and name in one level, any suggestions?

If you are asking if these can show up on the same line in the Node preview or a watch node, you are out of luck. This is just the way that Dynamo formats data/lists in the interface- each value in a list shows up on a separate line. (I actually find this easier to work with as there is no question of exactly what piece of data is “where” in a list of lists and sublists…)

You could further process the resulting data if you need them to show up together in a different context (text file, dialog box, excel). For example, you could convert both values into strings and then concatenate the strings. However, by doing that, you are no longer working with the original data.

Joe

1 Like

Would you use antoher Python code to export it to excel? Ho would it look like?

There are many nodes to export to excel- a quick search of the forum should help you figure out what you want to do, and there are probably examples.

Thank you very much :slight_smile:

If you’re ok with it being a single string you could use the str.format method in Python

if isinstance(IN[0], list):
    elements = UnwrapElement(IN[0])
else:
    elements = [UnwrapElement(IN[0])]

result = []
for e in elements:
    params = []
    for p in e.Parameters:
        params.append("{}: {}".format(p.Definition.Name, p.AsValueString()))

    result.append(params)  # Use sorted(params) if you want alphabetical order

OUT = result

image

1 Like

Hi,

another solution with Revit.Element (without unwrap inputs elements), using the string representation of objet Parameter

import sys
import clr
clr.AddReference('RevitNodes')
import Revit

# The inputs to this node will be stored as a list in the IN variables.
elements = IN[0]
OUT = [[x.ToString() for x in e.Parameters] for e in elements]
3 Likes