I am working in Family Document and i am trying to associate family paramter between a point paramter (“Offset” Built in paramter) with a family paramter (User define paramter)
I wrote this script but the last method is not accepting the input
# Import the necessary Dynamo and Revit libraries
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Import the Dynamo library for working with Revit elements
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *
clr.AddReference("RevitServices")
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager
# Define the Family document
doc = DocumentManager.Instance.CurrentDBDocument
# The inputs to this node will be stored as a list in the IN variables.
point = UnwrapElement(IN[0])
nameParamter = IN[1]
FamParameter = IN[2]
poi = []
fam = []
# Get the Element Parameter
point = UnwrapElement(IN[0])
pointParas = point.Parameters
for item in pointParas:
if item.Definition.Name == nameParamter:
poi.append(item)
# Get the Family Parameter
listPara = doc.FamilyManager.Parameters
for item in listPara:
if item.Definition.Name == FamParameter:
fam.append(item)
#code below this line
TransactionManager.Instance.EnsureInTransaction(doc)
doc.FamilyManager.AssociateElementParameterToFamilyParameter(poi,fam)
TransactionManager.Instance.TransactionTaskDone()
# Assign your output to the OUT variable.
OUT = fam
Hi @m.saleh.tum
It is helpful to provide a screen shot of the warning for additional context.
You are building lists for the parameters when the AssociateElementParameterToFamilyParameter
method accepts an element parameter and a family parameter
Rather than building lists and checking for parameters with a for loop you can use built in methods to get the parameters using their name such as poi = point.LookupParameter(nameParameter)
or poi = point.GetParameters(nameParameter)[0]
for a list if there are multiple parameters with the same name
Once we have our parameter we can check if it can be associated doc.FamilyManager.CanElementParameterBeAssociated(poi)
before proceeding
The FamilyManager is not so flexible so using a for loop to get the family parameter works. You could also do this with a list comprehension and take the first item fam = [p for p in doc.FamilyManager.Parameters if p.Definition.Name == FamParameter].pop(0)
So now we can try code like this
output = []
# Get the Element Parameter
point = UnwrapElement(IN[0])
poi = point.LookupParameter(nameParameter) # Note: fixed typo
output.append([poi.Definition.Name, poi])
if doc.FamilyManager.CanElementParameterBeAssociated(poi):
# Get the Family Parameter
fam = [p for p in doc.FamilyManager.Parameters if p.Definition.Name == FamParameter].pop(0)
output.append([fam.Definition.Name, fam])
TransactionManager.Instance.EnsureInTransaction(doc)
doc.FamilyManager.AssociateElementParameterToFamilyParameter(poi,fam)
TransactionManager.Instance.TransactionTaskDone()
OUT = output
1 Like