Setting Multiples Parameters in a Families using Python Script

Hello, how are you? Good afternoon everyone, again I am struggling with Python within Dynamo
So I wanted to see if any of you can support me.

The context is that I have a list of parameters and within those cells I want to assign values
The list of names is a simple list and the list of values ​​is a list of lists
I did some research on the web and I saw that with map the index can be traced, but I don’t know where I’m wrong, if someone can guide me I would appreciate it a lot
Could someone tell me that I am missing the syntax for the map to work correctly

I am using a dummy exercise of create beams and assign values, the files are here and the model is Revit 2021, for now I don’t write any result, so I think my problem is in the syntax of the map.

This is the image

This is the main part of the code where I think the problem is

level= doc.ActiveView.GenLevel
TransactionManager.Instance.EnsureInTransaction(doc)
BeamType.Activate()
for curve in curves:
	framing= doc.Create.NewFamilyInstance(curve.ToRevitType(), BeamType, level, Structure.StructuralType.Beam)
	framings.append(framing)
	for i,(par,val) in enumerate(zip(Parameters,Conv)):
		param= framing.LookupParameter(par)
		map(lambda x: param.Set(i), Conv)

This is the family, that you can upload in the Revit project W Shapes.rfa (1.3 MB)
Set-Beam-Type-01.dyn (19.3 KB)

Hello @Luiscko
at this line

for i,(par,val) in enumerate(zip(Parameters,Conv)):
	param= framing.LookupParameter(par)
  • val is a sublist of values (3 objects)

  • par is a string (1 object)

  • param is a parameter (1 object)

What unique value do you want assigned to your parameter ?

1 Like

@c.poupin the script is in the description if you want to check better.
You are right, par is a list with sublist, in this case a list of six elements with values in the sublist, the sublist is composed by the different values that I want to set for each framing.
When the parameter is equal to each other the code is pretty simple, but now I am trying to assign the different value in the list of framings, so each framing have his unique value for each parameter.

The problem is that you’re using the list of sublists at the level you should already have the individual element’s list of values. You need to pull out the sublist with your list of curves so that the list structure matches.

I think you want something more like this:

for curve,vals in zip(curves,Conv):
	
	
	for i,(par,val) in enumerate(zip(Parameters,vals)):
		param= framing.LookupParameter(par)
		map(lambda x: param.Set(i), val)

Even then, mapping probably isn’t necessary. You can just loop through values once you get your structure sorted out. I would do something more like this:

2 Likes

I try your approach but is not working because it does not put the values in the right way, but I think if I want to do your approach I need to sort my list differently, so let I try again, by the way the script is in the post if you want to review directly from the original code.

Your lists will definitely have to be sorted for any solution. Dynamo can’t guess at what goes with what.

1 Like

This was the final solution for three beam example:

import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('DSCoreNodes')
from DSCore import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

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

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

#Preparing input from dynamo to revit
curves=IN[0]
BeamType = UnwrapElement(IN[1])
framings= []
Parameters= ["Defu","Defm","Mu","Mn","Vu","Vn"]
Val=[[100,200,100,200,100,200],[200,400,200,400,200,400],[200,300,200,500,500,1000]]
UnitConv=[3.281,3.281,105602,105602,32175,32175]


def ConvertUnits(Units,Values):
	Conversion=[]
	for value in Values:
		templist=[]
		for val,unit in zip(value,Units):
			con= val*unit
			templist.append(con)
		Conversion.append(templist)
	return Conversion

ConvValues= ConvertUnits(UnitConv,Val)		
# Place your code below this line
doc = DocumentManager.Instance.CurrentDBDocument

#Do some action in a Transaction
level= doc.ActiveView.GenLevel
TransactionManager.Instance.EnsureInTransaction(doc)
BeamType.Activate()
for curve,Values in zip(curves,ConvValues):
	framing= doc.Create.NewFamilyInstance(curve.ToRevitType(), BeamType, level, Structure.StructuralType.Beam)
	framings.append(framing)
	for par,value in zip(Parameters,Values):
		param= framing.LookupParameter(par)
		param.Set(value)

TransactionManager.Instance.TransactionTaskDone()

#Outputs
OUT = ConvValues,framings
1 Like