Create Parameters in a Revit Family

Hi I think this is gonna be a easy one for you.
I replicated your code and it works flawlessly when trying to create One parameter. But how Do I run it to create Multiple Parameters. Say a list of Parameter Names.

1 Like

This is for one parameter type, Example is HVACDuct Size. If you have multiple kinds of parameter types like Length, Angle, Yes/No… You have to run each parameter type separately so that’s why you see the crossed out Await node.
You’ll need to create an excel file with all your parameters but put the different parameter types on their own sheets.
The code at the bottom is the red circled Python Node that you need to create to assign the formulas.


Create Params & Formulas excel1

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc =  DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

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

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

pNames = tolist(IN[0])
fString = tolist(IN[1])

outList = []
errors = []
test = []
names = []

if doc.IsFamilyDocument:
	fMan = doc.FamilyManager	
	params = fMan.GetParameters()
	for pName,fStr in zip(pNames,fString):
		for p in params:
			pd = p.Definition
			pn = pd.Name
			names.append(pn)
			if pName == pn:
				if p.CanAssignFormula:
					TransactionManager.Instance.EnsureInTransaction(doc)
					if fMan.IsParameterLocked(p):
						fMan.SetParameterLocked(p,False)					
					try:
						fMan.SetFormula(p,fStr)
						test.append(pn)
						outList.append("Succeeded")
					except Exception, e:
						outList.append(e)
					TransactionManager.Instance.TransactionTaskDone()
				else:
					errors.append(pn)
	
	no =  set(names).difference(set(test))
OUT = outList, no