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]