Group multiple elements, parameters, and values using Python

Hi,

I am trying to get/set the parameters (Comments, Mark) of multiple Revit elements. I can’t seem to make a group of [element, parameter, value] for the same.

def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)

# Preparing input from dynamo to revit
elems = uwlist(IN[0])
params = uwlist(IN[1])
pValues = uwlist(IN[2])
outlist = []

TransactionManager.Instance.EnsureInTransaction(doc)
for e in elems:
	for p, pv in zip(params, pValues):
		outlist.append([e,p,pv])
TransactionManager.Instance.TransactionTaskDone()

OUT = outlist

Hi,

I think you are nesting your lists, is that what you want?

I’d presume you want them separately?

I’m not sure, but it might be that the use of a list created inside the first For Loop gives you the structure you are wanting?

Whether a list is created inside or outside the For Loop affects its behaviour.

Hope that helps,

Mark

1 Like

Well, the problem here is the parameter values. Instead of doing transpose and flatten on the Parameter Values, I want to use them directly in Python.

def tolist(input):
    result = input if isinstance(input, list) else [input]
    return result

def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)

# Preparing input from dynamo to revit
elements = uwlist(IN[0])
params = tolist(IN[1])
values = tolist(IN[2])

rParams = []
rValues = []
rElements = []
for e in elements:
	for p in params:
		rParams1 = e.LookupParameter(p)
		rParams.append(rParams1)
		rValues1 = rParams1.AsString()
		rValues.append(rValues1)
		rElements.append(e)

rParamsName = []

for p in rParams:
	rParamsName.append(p.Definition.Name)

TransactionManager.Instance.EnsureInTransaction(doc)

for p,v in zip(rParams, values):
	p.Set(v)

TransactionManager.Instance.TransactionTaskDone()

OUT = rElements, rParamsName, rValues

try this?

def tolist(input):
    result = input if isinstance(input, list) else [input]
    return result

def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)

# Preparing input from dynamo to revit
elements = uwlist(IN[0])
params = tolist(IN[1])
values = tolist(IN[2])

TransactionManager.Instance.EnsureInTransaction(doc)

rParams = []
rValues = []
rElements = []
for i, e in enumerate(elements):
	for j, p in enumerate(params):
        rParams1 = e.LookupParameter(p)
		rParams.append(rParams1)
		rValues1 = rParams1.AsString()
		rValues.append(rValues1)
		rElements.append(e)
        rParams1.Set(values[j][i])

rParamsName = []
for p in rParams:
	rParamsName.append(p.Definition.Name)

TransactionManager.Instance.TransactionTaskDone()

OUT = rElements, rParamsName, rValues
1 Like

It’s only setting the parameter values of the last parameter.

I don’t know what you want to achieve, let others to help you maybe :slight_smile:

It worked. Just need to move this line of code rParams1.Set(values[j][i]) up so the parameter value is set as soon as the parameter is grabbed from API.

def tolist(input):
    result = input if isinstance(input, list) else [input]
    return result

def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)

# Preparing input from dynamo to revit
elements = uwlist(IN[0])
params = tolist(IN[1])
values = tolist(IN[2])

TransactionManager.Instance.EnsureInTransaction(doc)

rParams = []
rValues = []
rElements = []
for i, e in enumerate(elements):
	for j, p in enumerate(params):
		rParams1 = e.LookupParameter(p)
		rParams1.Set(values[j][i])		
		rParams.append(rParams1)
		rValues1 = rParams1.AsString()
		rValues.append(rValues1)
		rElements.append(e)
rParamsName = []
for p in rParams:
	rParamsName.append(p.Definition.Name)

TransactionManager.Instance.TransactionTaskDone()

OUT = rElements, rParamsName, rValues

so strange, the sequence should have no influence in here :face_with_monocle: they are in same loop, dont know why, but anyway happy you figured it out :slight_smile:

1 Like