Associate family parameter in a family

Hello everybody,

I am new to dynamo programming and I do not know Python as well but I was trying to associate an element (generic model form) Material parameter with a Material parameter inside the Family Types dialog while in Family editor mode. I would like to use this script but I do not know how I could change it to make it work.
Could I get any help from you guys?

I made it after some tries :slight_smile:
Is there a way also to use this to fill the data from the Family Types Parameters?

Yes I found them and they have worked just fine. Thank you for your quick response, this forum is great.

I want/need to take this one step further.

Best practice is when you make a family that you set the material to a parameter. So the material parameter is connected (with the grey box) to a instance or type material parameter so you can adjust the material of the extrusion in the parameter fields.

I am greating a window out of profiles and lines and assign a material to it… But i want to assign a parameter to that material slot.

Is this possible…
This is the family with the created window family in it…i want the parameter frame_material connected to the material parameter of that family…

the next step is to connect the frame_material parameter to the kozijn_material in the host family

kozijn_generator_joris.rfa (2.6 MB)

Hey @awilliams did you or @3Pinter every work out how to use code for a nested list of elements as well as a list or nested list of types etc. Works great with a single list of elements but not more. I had a look at running it though a loop to pull the nested list apart but the code seems to have lots of levels of Zip’s / dictionaries. Which i am yet to get my head around as the lists maybe different lengths.

Currently just splitting the nested list outside the python node to get it to work but that somewhat limits the number of types as don’t really want to copy and paste the node 10+ times if i can use a nested list structure in a loop inside the code.

just attempted and I think the python needs another lay of looping. ex: line 29
would change from:
for e in elements:
e = UnwrapElement(e)
elemParams = e.Parameters

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

tossing this here just incase. pythons not my main code langue so can’t guarantee this works outside of my needs. It iterates over a list of parameters and a list of elements “shortest” (setting 5 filled regions “visibility” to 5 different Yes/No Parameters)

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

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

elem = UnwrapElement(IN[0])
paramNames = IN[1]
famNames = IN[2]

if not isinstance(paramNames, list):
	paramNames = [paramNames]
if not isinstance(famNames, list):
	famNames = [famNames]
famParams = doc.FamilyManager.Parameters
#tester =[]
ii = 0
famAssoc = []
testout =[]
for fparam in famParams:
		#tester.append(fparam.Definition.Name)
		for fname in famNames:
			if fparam.Definition.Name == fname:
				testout.append(fparam.Definition.Name)
				famAssoc.append(fparam)
for e in elem:
	elemParams = e.Parameters
	
	elemAssoc = []

	
	ll = []
	for param in elemParams:
		for name in paramNames:
			if param.Definition.Name == name:
				elemAssoc.append(param)
				
	

	TransactionManager.Instance.EnsureInTransaction(doc)	
	for i in elemAssoc:
		
		try:
			doc.FamilyManager.AssociateElementParameterToFamilyParameter(i, famAssoc[ii])
			#doc.FamilyManager.CanElementParameterBeAssociated(i,j)		
			error_report = "No errors"
			
		except:
			error_report = "can't assign parameter"
	TransactionManager.Instance.TransactionTaskDone()
	
	l =[]

	ii=ii+1

OUT = elem, error_report, testout, famAssoc, l, elemAssoc