How to find out if parameter of a wall has been set a Global Parameter

Hi,

I can’t find out how to get if parameter of a wall has been set a Global Parameter.

My goal is to select some walls without global parameter and filter by “Desfase superior” in order to put a global parameter to walls without any global parameter.

I see same links of how to set a global Parameter as a Parameter of a element but i can’t find examples of my problem.

I found in the RevitApiDocs that there is a method GetAffectedElements() but i don’t know how to use it.

Thank in advance.

1 Like

@pmerryason ,

i can not solve the issue… thats the nearest progress

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
bool = GlobalParametersManager.AreGlobalParametersAllowed(doc)
gparams = GlobalParametersManager.GetAllGlobalParameters(doc)

collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType()
elements = list(collector)


OUT = bool, gparams

grafik

KR

Andreas

Once you have the global parameter as say the variable globalParam, use globalParam. GetAffectedElements() to pull all element ids impacted by the global parameter. Note that is a list of ids, so you’ll have to fetch the element from the document if you want elements. Give it a shot and see where you get. :slight_smile:

1 Like

@jacob.small

You haven’t yet gathered any global parameters. Just a collection of element IDs.

@jacob.small

but i have them already…

how do i test the “Affection” via my elements(walls) or does the parameters “know” there connections ?

No - check the link carefully. The method returns element IDs not the elements. :wink:

@jacob.small ,

grafik

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

from Autodesk.Revit.DB import ElementId, Element, BuiltInCategory, FilteredElementCollector


doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
bool = GlobalParametersManager.AreGlobalParametersAllowed(doc)
gparams = GlobalParametersManager.GetAllGlobalParameters(doc)


collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType()
elements = list(collector)

basket = []

for i in elements:
	basket.append(i.Id)
	
affected = []
	

for wall_id in basket:
	affected_elements = GetAffectedElements(ElementId(wall_id))
	affected.extend(affected_elements)

OUT = bool, gparams, basket, affected

hmmmm … :wink: (last part is ChatGPT, but it is still not usefull)

Thank you so much for your help.
A little progress


Now we have global parameter elements but no the affected elements.

1 Like

elements.append(doc.GetAffectedElements(gparam))   //last pracket were missed

@pmerryason

Still not collecting the global parameter elements. You’ve got the element ids for your global parameters at the line gparams = GlobalParametersManager.GetAllGlobalParameters(doc). But if you want the paramet er elements you need to do something like this:

gparamElements = [doc.GetElement(id) for id in GlobalParametersManager.GetAllGlobalParameters(doc)]

Once you have the actual elements you can call the methods fo the class on them.

But these are again element IDs, not elements. And so we likely want to select the elements using the IDs again. Note this is a nested list so the list comprehension gets nested as well.

Resulting code (less imports):

doc = DocumentManager.Instance.CurrentDBDocument

gparams = GlobalParametersManager.GetAllGlobalParameters(doc)
gparamElements = [doc.GetElement(id) for id in GlobalParametersManager.GetAllGlobalParameters(doc)]
affectedElementIdLists = [ gparamElement.GetAffectedElements() for gparamElement in gparamElements ]
affectedElements = [[doc.GetElement(id) for id in affectedElementIds] for affectedElementIds in affectedElementIdLists]

OUT = affectedElements 
4 Likes

@jacob.small

it works finally

Great… now that all of that is out of the way, a quick lesson:

Practice Interrogating what you have at various steps.

  • Using python tools like like dir(thing), thing.__class__, and thing.__doc__ is more effective than chat gpt 100% of the time, and more effective than going to the forum.

Next, we still haven’t answered the original question: How to find out if a particular parameter of a wall is impacted by a global parameter. This code will do that, taking into account that an element can have multiple parameters with the same name and just checking them all…

elems = UnwrapElement(IN[0])
paramName = IN[1]
unassocaited = []
for elem in elems: #for every element in the element list:
    params = [i for i in elem.Parameters] #get the parameters 
    matchingParamList = [p for p in params if p.Definition.Name == paramName] #get parameters with matching names
    globalParams = [ param.GetAssociatedGlobalParameter() for param in matchingParamList] #get the associated global parameter for each parameter
    if ElementId(-1) in globalParams: unassocaited.append(elem) #if there is an invalid element id (-1) in the list of global parameter associations, append the element to the list of unassocaited elements
OUT = unassocaited
4 Likes

What a help!!!
Thank you so much!

2 Likes