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.
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.
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)]
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.
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
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