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

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

@moore.spencer, I am trying to do something similar but when I copy the code snippet, in the loop, the portion after the “myparam =” does not copy… Can you tell me what I need to add here?

Hi CADR, I believe it is just an empty list. Try using using an open and closed bracket “”

Let me know if that works and I will update the code.

thanks - I tried that ( ) similar to what it was in the single selection version posted prior, but it did not work for me in the looping version.
(Its weird how it does not select when copying from the snip, but I am new to the forums, so… user error is entirely possible :0)

Try putting an open bracket and a closed bracket together. The site is formatting that to be a certain character, which when copy and pasted in, will disappear.

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 = [delete_all_of_this_except_brackets_when_pasting_in]

#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

thanks for your help. (I really appreciate it)
it seems like the entire snip has lost its formatting (note indents missing etc. when compared to previous.) I believe the indents are needed???

I have tried adding in the indents (similar to previous), adding the brackets for the empty variable myparam, etc. but I just haven’t found the right combination yet…
again - I am new to the forum so maybe I am missing something?

Here is what I have done, but its still not working.

I apologize for the confusion and thanks for bearing with me; I haven’t been on the forums for a few years so. It should just be a simple copy and paste from the forums, but I didn’t check the formatting when posting it, so apologies there too. I changed companies a few years back so I am trying to jog my memory as to how I used it back then.

Some items with your code:

  • I see that line 66 OUT = 0: you can just delete everything below line 65, see attached screenshot. I will try to format the code and re-post. Make sure that when you copy+paste that you replace all of the existing text with this code, unless you are have another reason to.

Also, what error is it giving you?

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

#Inputs
name = IN[2]
gp = IN[1]
l1 = UnwrapElement(IN[0])

#Loop
for elements in l1:
#Get parameters from element
parameters = elements.Parameters
myparam = 

#start transaction
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”

#end transaction
TransactionManager.Instance.TransactionTaskDone()

#Output
OUT = out

I apologize I can’t figure out the formatting and don’t have the time, but here is what it is supposed to look like, see attached. This is meant to do multiple elements. It won’t work with a single element. And it was designed for type parameters of families; haven’t tested it with instance parameters, but I don’t imagine that would be an issue.

I was getting an Unexpected token error (which I believe is a formatting or syntax issue?)

after reviewing your code, I was able to get mine to work by adjusting the format and for some reason my transaction start was outside of the loop… (not sure how?) anyway - thanks to your help I was able to get it to work!

Thanks again for helping me with this - I really appreciate it!

1 Like

Hi @moore.spencer,

I get the error message below when I use the Python script.
Any idea what this could be?
Thanks in advance!

Here is the code formatted correctly. Some of the string arguments weren’t being interpreted correctly and it wasn’t correctly indented. The code isn’t very clean as the transaction is probably in the wrong place in the loop, and some other unconventional practices, but it works for now.

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

#Inputs
name = IN[2]
gp = IN[1]
l1 = UnwrapElement(IN[0])

loop
for elements in l1:
#Get parameters from element
parameters = elements.Parameters
myparam =

#start transaction
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"

#end transaction
TransactionManager.Instance.TransactionTaskDone()

#Output
OUT = out

1 Like

THANK YOU so much for this thread!!! I’m trying to assign a global parameter to a beam family type parameter. I’m getting the python to run without errors. Any ideas why it’s not working? Are there limitations to this code that I’m missing?

Add global parameter.dyn (17.1 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

The inputs to this node will be stored as a list in the IN variables.

name = IN[2]
gp = IN[1]
l1 = UnwrapElement(IN[0])
out =
for elements in l1:
#Get parameters from element
parameters = elements.Parameters
myparam =

#start transaction
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 = "sucess"
    except :
        out = "fail"

#end transaction
TransactionManager.Instance.TransactionTaskDone()

#Output
OUT = out