Python script unable to take multiple items from list

For some reason I couldn’t get multiple item list inputs for the last python script working. While singular input into it works just. Any ideas why this is happening? Thanks

Any python guru’s got any ideas?

The TypeError tells you that you’re giving it a list instead of a string. You’re using a conditional statement to ensure that your revs variable is always a list, but you should try to do a similar approach with your second input.

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

def set_description(r, val):
    UnwrapElement(r).Description = val
    return r

revs = IN[0]
new_description = IN[1]
if not isinstance(revs, list): # Ensure revs is always a list
    revs = [revs]
if isinstance(new_description, list): # Ensure new_description is always a string
    new_description = ' '.join(new_description)

TransactionManager.Instance.EnsureInTransaction(doc)
output = [set_description(rev, new_description) for rev in revs]
TransactionManager.Instance.TransactionTaskDone()

OUT = output

I don’t have access to Revit or Dynamo on my personal PC so I haven’t tested the above code, but it should work. I essentially just added an if statement to test whether the new description is a list and, if it is, it will join all of the items into a single string with a space between each item.

If you’re trying to assign a description to each respective Revision, you’ll have to do it slightly differently:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

def set_description(r, val):
    UnwrapElement(r).Description = val
    return r

revs = IN[0]
new_description = IN[1]
if not isinstance(revs, list): # Ensure revs is always a list
    revs = [revs]
if not isinstance(new_description, list): # Ensure new_description is always a list
    new_description = [new_description]

output = []
TransactionManager.Instance.EnsureInTransaction(doc)
for rev, desc in zip(revs, new_description):
    output.append(set_description(rev, desc))
TransactionManager.Instance.TransactionTaskDone()

OUT = output
2 Likes