Revit and Dynamo 2023 with Element.SetParameterByName

Well I’ll be damned… Revit 2023 out for 4 months and the set parameter node can’t handle integers. Yikes.

Try this Python based approach as an alternative.

Set integers.dyn (13.3 KB)

# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

# Boilerplate text
import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

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

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

# Define list/unwrap list functions
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])
pname     = IN[1]
pvals     = tolist(IN[2])

results = []

# Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

for e,v in zip(elements,pvals):
    param = e.LookupParameter(pname)
    try:
        param.Set(v)
        results.append(True)
    except:
        results.append(False)

TransactionManager.Instance.TransactionTaskDone()

# Output and Changing element to Dynamo for export
# <element>.ToDSType(True), #Not created in script, mark as Revit-owned
# <element>.ToDSType(False) #Created in script, mark as non-Revit-owned

# Preparing output to Dynamo
OUT = [elements,results]
3 Likes