Associate family parameter to connector element


#1

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!


#2

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)


#3

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.


#4

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.


#5

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.


#6

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


#7

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??


#8

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.


#9

@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?


#10

That’s it!
Solved my problem!
Thank you!!!