Set different values to the same parameter depending on the type

Hey, as I said I’m trying to add different values to a parameter depending on the type via a python script but something seems not right about the code… Maybe someone could help me figuring out what is wrong.

Here with a test family trying to change the value for 3 types

import clr

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

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

# Current doc/app/ui
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application

# Define list/unwrap list functions
def tolist(input):
    result = input if isinstance(input, list) else [input]
    return result

# Preparing input from dynamo to revit
path_list = tolist(IN[0])
type_list = tolist(IN[1])
value_list = tolist(IN[3])

# Track what happens
results = []
controll = []

# For each family file path
for path in path_list:
	
	# Open the family, get its name
	doc = app.OpenDocumentFile(path)
	docT = doc.Title
	
	# Get the family manager, and a subresult
	famMan = doc.FamilyManager
	famResult = []
	
	# Start a Revit transaction
	t = Transaction(doc, 'docT')
	t.Start()
	
	# Get all parameters in the document
	params = doc.FamilyManager.Parameters
	# Get all types in the document
	types = doc.FamilyManager.Types
	
	# For each type
	for type in types:
		# Get the types name
		t_nam = type.Name
		controll.append(t_nam)
		# If the type is in your list of names
		if t_nam in type_list:
			try:
				for param in params:
					if param.Definition.Name == IN[2]:
						famMan.FamilyManager.Set(param,value_list[param])
			except:
				results.append("Failed")

	# Finish a Revit transaction
	t.Commit()
	
	# Append the outcome
	results.append(famResult)
	
	# Close and save the document
	doc.Close(True)

# Preparing output to Dynamo
OUT = [results, controll]
1 Like

I think I see a couple possibilities here.
Seems like
famMan.FamilyMananger.Set should just be famMan.Set

Also it looks like you’re treating value_list like a dictionary and trying to feed it a key, param, which won’t work because it’s just a list. You need to feed it an integer index value.

As an aside, try/except can obviously be very handy, but it’s a double edged sword. If you took out that try/except clause, the python node would give you an error message that would help you troubleshoot where the error is.

2 Likes