Associating Global Parameters to a multiple family types in a project

I want the graph to associate multiple furniture-category family types (which share the same single YesNo - type parameter) to a global YesNo parameter.

From this post (Associating Global Parameters to a family in a project), I want to associate a global parameter to multiple family types simultaneously.

associate global params to elements.dyn (11.2 KB)

import clr

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

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

clr.AddReference('System')
from System.Collections.Generic import List

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

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

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

element = UnwrapElement(IN[0])
name = IN[1]
gp = IN[2]

#Get parameters from element
parameters = element.Parameters
myparam = []

TransactionManager.Instance.EnsureInTransaction(doc)

#Get parameters with the input name
for param in parameters:
    if param.Definition.Name == name:
        myparam.append(param)

#Associate parameter
for x in myparam:
    try:
        x.AssociateWithGlobalParameter(ElementId(gp.Id))
        out = "Success"
    except:
        out = "Fail"

TransactionManager.Instance.TransactionTaskDone()

OUT = out

More info:
Context:
-I specialize in furniture and security plans for my company. We use generic annotations to label the furniture and we also use generic annotations for our security symbols. In our furniture plans, we would only like the furniture labels to show, and since labels and text can’t be assigned subcategories, they are stuck at the “Generic Annotation” category. Our security plans show our furniture labels and it looks very messy.

Solution:
I am searching for a way, using dynamo and python, to associate the furniture labels.
-The furniture labels are toggled via a YesNo FamilyType Parameter
-I would like my users to use the dynamo player to automatically associate the family type parameter to a global parameter in their projects.
-We have multiple furniture families and types, so it would need to receive a list of (unique) family types which it will then associate to a global parameter, so that non-dynamo savvy users can automate this process.
-I have tried using the Orchid Package “Parameter.Associate” and a custom python script and it seems to only take one family type at a time. (thanks to this post)
–I wonder if I just need add a loop for the IN[0] to make it work.

If it’s not too difficult / unreasonable, I am calling for erfajo

I actually showed this by the example you are referring to

It should be doable to changed into a yes/no parameter since it is almost the same as a text parameter… it just takes a 0 or 1 as its values (false/true)

2 Likes

Thank you for the quick reply.

I will be sure to include the graph in future posts.

edit: it didn’t really solve my issue: I wanted the graph to associate multiple furniture-category family types (which share the same single YesNo - type parameter) to a global YesNo parameter.

My guess is that it won’t work for multiple type parameters at the same time. It is picky on certain categories.

associate global params to elements.dyn (8.1 KB)

1 Like

Thank you for the help and the tip!!! I’m still fairly new to the forums.

1 Like

This is the code if you want to take in a list of elements, rather than just single elements

import clr

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

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

clr.AddReference(‘System’)
from System.Collections.Generic import List

clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

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

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

elements = UnwrapElement(IN[0])
name = IN[1]
gp = IN[2]

TransactionManager.Instance.EnsureInTransaction(doc)

#loop through list of elements
for element in elements:

#Get parameters from element
parameters = element.Parameters
myparam =

#Get parameters with the input name
for param in parameters:
if param.Definition.Name == name:
myparam.append(param)

#Associate parameter
for x in myparam:
try:
x.AssociateWithGlobalParameter(ElementId(gp.Id))
out = “Success”
except:
out = “Fail”

TransactionManager.Instance.TransactionTaskDone()

OUT = out