I want the graph to associate multiple furniture-category family types (which share the same single YesNo - type parameter) to a global YesNo parameter.
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 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.
@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?
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.
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.
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.
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!
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
#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()
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?