Associate family parameter to connector element

So i have to assign a parameter i created in a family to a connector element autommatically through dynamo, is there a way to do that?
Thank you!

I tryed doing this, but it didnt work. Iā€™ll post de dyn file with the family fileAtribuir Diametros aos conectores.dyn (14.0 KB)
Caixa de Passagem 4x4.rfa (536 KB)

Well, i donā€™t know anything about python script. But i couldnā€™t make it work for a list of elements, but i tried to do it for each element in a listā€¦ creating a lot of nodes for doing so, and it worked.

Hi @ramoon.bandeira ,

I had a look at your script

  •   I deleted the ā€œcreate parameter partā€, since the parameters are already there.
    
  •   I got no errors
    
  •   The 4 connector elements (not being 20) are assigned properly.
    

No need to create additional nodes in my opinion! See attached.

1 Like

The dynamo code does not return any errors, but if you go to the family after the script execution, you will see that that all 4 connectors are associated with parameter C1. When it should be:
Connector 1 associated to C1;
Connector 2 associated to C2;
Connector 3 associated to C3;
Connector 4 associated to C4;
Thats why i have to repeat it for everysingle parameter association.

by the way, the script in that python node is the following:

import clr
clr.AddReference(ā€˜RevitAPIā€™)
from Autodesk.Revit.DB import *

clr.AddReference(ā€˜RevitNodesā€™)

import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference(ā€˜RevitServicesā€™)
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

elements = IN[0]
epSearch = IN[1]
fpSearch = IN[2]

if not isinstance(elements, list):
elements = [elements]
if not isinstance(epSearch, list):
epSearch = [epSearch]
if not isinstance(fpSearch, list):
fpSearch = [fpSearch]

for e in elements:
e = UnwrapElement(e)
elemParams = e.Parameters

epNames = []
fpNames = []
elemAssoc = []
famAssoc = []

for ep in elemParams:
	epNames.append(ep.Definition.Name)
	
epDict = dict(zip(epNames,elemParams))
elemAssoc = [epDict.get(ep, "none") for ep in epSearch]

famParams = doc.FamilyManager.Parameters

for fp in famParams:
	fpNames.append(fp.Definition.Name)
	
fpDict = dict(zip(fpNames,famParams))
famAssoc = [fpDict.get(fp,"none") for fp in fpSearch]


TransactionManager.Instance.EnsureInTransaction(doc)

for i,j in zip(elemAssoc,famAssoc):
	try:
		doc.FamilyManager.AssociateElementParameterToFamilyParameter(i, j)
		error_report = "No errors"
		
	except:
		error_report = "can't assign parameter"
TransactionManager.Instance.TransactionTaskDone()

OUT = elements,error_report

You are assigning to element instance ā€œConnectorElementā€ with instance familyparameter ā€˜Diameterā€™ the Familyparameter c1, c2, c3, c4.

So it will grab the first item in famParameterNames list ā€¦ and then stops.
Changing elemParameterNames to { Diameter, Diameter, Diameter, Diameter } will result in 4 times c4 assigned.

The way it works is if you have c1, c2, c3, c4 parameters available in your elementinstances (connector element) ā€¦ so assining c1 of your family will trigger the element instance c1 too. etc. (unsure if you can assign / alter a connector element though)

Or do I misunderstand your question?

Or if connector 1 associated to C1 ā€¦ what is connector 1? itā€™s not defined?? Or is a random connector assigned to c1??

lets summarize the code:
after filtering the connectors, what remains are these four connectors, i created 4 instances parameters and i will associate Family parameter C1 to conduit connector (wich i labeled C1 in the picture) Diameter Parameter, then i will associate Family parameter C2 to conduit connector (wich i labeled C2 in the picture) Diameter Parameterā€¦ and so on
Thatā€™s what iā€™m trying to do.

@ramoon.bandeira,

you could add fpSearch.pop(0) after you did your first assignment.

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

clr.AddReference('RevitNodes')

import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

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

doc = DocumentManager.Instance.CurrentDBDocument


elements = IN[0]
epSearch = IN[1]
fpSearch = IN[2]

if not isinstance(elements, list):
	elements = [elements]
if not isinstance(epSearch, list):
	epSearch = [epSearch]
if not isinstance(fpSearch, list):
	fpSearch = [fpSearch]

for e in elements:
	e = UnwrapElement(e)
	elemParams = e.Parameters

	epNames = []
	fpNames = []
	elemAssoc = []
	famAssoc = []
	
	for ep in elemParams:
		epNames.append(ep.Definition.Name)
		
	epDict = dict(zip(epNames,elemParams))
	elemAssoc = [epDict.get(ep, "none") for ep in epSearch]
	
	famParams = doc.FamilyManager.Parameters
	
	for fp in famParams:
		fpNames.append(fp.Definition.Name)
		
	fpDict = dict(zip(fpNames,famParams))
	famAssoc = [fpDict.get(fp,"none") for fp in fpSearch]
	

	TransactionManager.Instance.EnsureInTransaction(doc)
	
	for i,j in zip(elemAssoc,famAssoc):
		try:
			doc.FamilyManager.AssociateElementParameterToFamilyParameter(i, j)
			error_report = "No errors"
			fpSearch.pop(0)			
			
		except:
			error_report = "can't assign parameter"
	TransactionManager.Instance.TransactionTaskDone()


OUT = elements,error_report

So it assigns, removes first item, assigns, removes first item etc.etc. Now 4 connectors have individual c1,c2,c3,c4 assigned. The order of this isnā€™t set obvious.

Does this help you?

1 Like

Thatā€™s it!
Solved my problem!
Thank you!!!