I tried searching topics about shared parameters and found out that most of them are “create and add to project” my question is how about removing or deleting unused shared parameters? I’ve experienced working with the project that has the same parameter names. Any idea on how to sort parameter that has no value or just a duplicate?
@interactiverendering I was searching and was about to create the same topic but found this. Any update as to a solution?
Element.Parameters yields little distinguishable info to determine is used or not.
I believe it would be a wicked problem to solve, as how does one tell if a shared parameter is not being used? A parameter such as a boolean could be on/off for example - is it not in use if it is off?
The only method I can think of is it to collect all elements, use ‘get parameter value’ and ensure there are no filled versions of the parameter. Then the user would need to elect if it is safe to remove. It seems too risky otherwise.
Old topic, I know. regarding this, I would like to know how I can filter out allready deleted shared parameters? Actually, if you delete them manually in revit, you will still find them with with Dynamo, there is a ton of duplicates. Would be nice if I could filter all the “deleted” shared parameters.
I had a similar situation.
I’ve imported a few families into my project, than, after a few months deleted (replaced with family parameters) their shared parameters.
I actually used @GavC’s Crumple package for that (and Orchid)
So i improvised, and exported all the parameters from that family (now when they are family parameters) and added them to a new script to delete the shared parameters in project:
@interactiverendering you can remove the parameters like this too, but you will probably need to write them down one by one by hand. if you don’t know their origin family
addendum:
You can create a Multiple Category Schedule, export it, and then open it with Excel.
Then copy the second row into Notepad++
Format the text as a list for dynamo (helpful: Notepad++ add to every line - Stack Overflow)
and run the above script
Reviving an old thread- same issue today when changing shared project parameters from NUMBER to AREA - and got :
the manual solution was use Snoop and look up each shared parameter (See Purge Shared Parameters From a Revit Model | OpenDefinery/Blog )
Then Select by ID and DELETE manually.
Really irritating deleting the parameter form project parameters does not delete them from the “Shared parameters”
So each one of those IDs must be deleted (search by IDs, then press DELETE). What we need is Autodesk to purge those after they have been removed from project parameters on a purge. Ideally after deleting the project parameters. It seems like a BUG IMO-
If the DYN were to delete any parameters that weren’t associated with andy project items or families- that would be it. But is that possible?
Not sure I follow what you’re after. Can you post an RVT in a new thread (linking here) with a data set to test on? Keep it to one unused shared parameter and one used shared parameter so we can confirm an initial POC.
Not too long ago I had a similar issue and I found that if I just iterated all ParamerElements and did a string equality on the param name I could then delete both and the Shared param would be gone. Now, that doesn’t check usage, but it was much faster than hunting ids in lookup.
This is because behind the scenes the binding remains. I believe amongst other reasons this relates to a parameter being able to remain in project schedules as a field post deletion. A good proof for this is;
Add a shared project parameter
Detele it from the model
In the shared param file, change its name but not its guid (bad I know)
Add it again
Its name will still be the old one. The model remembers it despite it being deleted. As you found the only way to get rid of them is targetting that Id behind the scenes.
Quick point of clarity - it’s not the bindings that remain, but the definition (which is defined by the shared parameter, which is defined by the GUID not the name). I believe that this is to prevent family data loss as the family elements may still need this data point to not go crazy if you do something like save out the family.
The code above (behind a spoiler as I’d qualify this as “dangerous to the point of not being recommended for for production”) should allow purging the definitions (via the shared parameter elements) if they are not in the bindings map (project parameters).
Hi,
an example solution with Python (only for instance parameters project), using the HasValue property
import sys
import clr
import System
from System.Collections.Generic import List
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Force close any open transactions to ensure a clean slate
TransactionManager.Instance.ForceCloseTransaction()
# Get the parameter bindings of the document
bindingMap = doc.ParameterBindings
iterator = doc.ParameterBindings.ForwardIterator()
def_toRemove = []
result = []
while iterator.MoveNext():
definition = iterator.Key
binding = iterator.Current
if definition.IsValidObject:
if isinstance(binding, InstanceBinding):
categories = binding.Categories
# Create a filter to select elements in the categories of the binding
filterCats = ElementMulticategoryFilter(List[ElementId]([cat.Id for cat in categories]))
# Create a predicate to filter elements that have a value for the current parameter definition
filterByHasValue = System.Predicate[System.Object](lambda x : x.get_Parameter(definition) is not None and x.get_Parameter(definition).HasValue)
# Find all elements that have a null value for the current parameter definition
instanceNullValues = List[DB.Element](FilteredElementCollector(doc).WherePasses(filterCats).WhereElementIsNotElementType().ToElements()).FindAll(filterByHasValue)
if len(instanceNullValues) == 0:
def_toRemove.append(definition)
# Start a transaction to remove the parameter definitions
t = Transaction(doc, "Remove Parameters")
t.Start()
for def_ in def_toRemove:
#
if hasattr(def_, "Id"):
filterbyId = System.Predicate[System.Object](lambda x : x.Id == def_.Id)
# for all Parameters
#param_elem = List[DB.Element](FilteredElementCollector(doc).OfClass(ParameterElement).WhereElementIsNotElementType().ToElements()).Find(filterbyId)
# for only SharedParameters
param_elem = List[DB.Element](FilteredElementCollector(doc).OfClass(SharedParameterElement).WhereElementIsNotElementType().ToElements()).Find(filterbyId)
if param_elem is not None:
doc.Delete(param_elem.Id)
result.append("Project Parameter '{}' removed".format(def_.Name))
t.Commit()
t.Dispose()
OUT = result