Hi everyone,
I’ve been trying to create a graph that detects unused parameters and deletes them. I’ve come so far to filter out the parameters which contain a value and those that don’t (now I have two separate lists with one containing all parameters with a value and one lists with all the parameters without a value). The problem now is that if several elements have the same parameter, but this parameter does not always have a value for all elements, the parameter appears in both lists (the list with all parameters with a value and the list with parameters without a value). And if I delete the parameter in the model, it deletes the parameter for all elements independent of whether it has a value or not. I want to know how one can override that information so that if the same parameter has a value somewhere it automatically overrides the same parameter without a value. The aim is to only have the parameter in the list when it has a value, at least for one element.
Something to try:
From ALL ELEMENTS (literally everything, which is hard to do as it’s Types, instances, and stuff you can’t necessarily select by a single node - your dropdowns list is going to be extensive).
Then use an Element.Parameters to get a list of all parameters associated to each element.
Then use a Parameter.HasValue to see which of the parameters have a value for each element (warning: You’re going to have 100,000’s of values here).
Then use a Parameter.Id to get the element ID for each parameter (not the value).
Then use a List.GroupByKey node to group all the ‘has value’ nodes by their ID.
Then use a List.AnyTrue or List.AllFalse node to a True/False value for each parameter, returning true only with everything is false from the grouped HasValue nodes.
Next use a List.FilterByBoolMask to get a list of all aprameters with which didn’t ever have a value (the list is the key from the GroupByKey and the mask is the result of the AllFalse/AnyTrue node).
Now get the parameter element and try to delete it - you might have some you cannot (Built In Parameters).
This won’t be quick, and there are likely better ways via the Revit API but this was framed as a Dynamo question so I’m assuming Nodes are your method of authoring. For something direct in the Revit API have a look at this: Delete unused Parameters, how - #2 by c.poupin