Delete unused Parameters, how


i want to delete Project parameters (shared) which are not in use:

they are in the project but not “activated”

[Zombie Parameters linger after delete from project parameters](https://Zombie Parameter)

Is there a related topic or even already solved?

with this script i have warnings?

import clr
import sys
# Import DocumentManager and TransactionManager
#Jacob Small 2023-03-28
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import relevant sections of the RevitAPI
from Autodesk.Revit.DB import Document, SharedParameterElement, FilteredElementCollector
doc = DocumentManager.Instance.CurrentDBDocument #the active document 
TransactionManager.Instance.EnsureInTransaction(doc)# Start Transaction

bindings = doc.ParameterBindings #get all the parameter bindings in the document
sharedParameters = FilteredElementCollector( doc ).OfClass(SharedParameterElement).ToElements() #get all shared parameters in the document
results = []                            #an empty list for our results
for sp in sharedParameters:             #for eveyr shared parameter perfor the following
    spDef = sp.GetDefinition()          #get the definition of the shared parameter
    test = bindings.Contains(spDef)     #test if the bindings map contains the defintion
    name = sp.Name                      #get the name of the shared paramter
    for Fpre in FilterPrefix:           #For each prefix matching in list
        ParamDelete = False
        if name[:len(Fpre)]==Fpre:    #Filter out prefixes
            if not test:                #if the definition was not in the bindings map
                ParamDelete = True
                results.append("--Deleted : {0}".format(name)) #let us know the parameter has been deleted
                results.append("___In Use : {0}".format(name)) #let us know the parameter is in use
        if len(FilterPrefix_ForcePurge) > 0 : ##items in list
            for FpreForce in FilterPrefix_ForcePurge :
                if FpreForce>"" and name[:len(FpreForce)]==FpreForce:
                    ParamDelete = True
                    results.append("-DelForce : {0}".format(name)) #let us know the parameter has been deleted  
        if ParamDelete:                 ##Delete Parameters
            ParamDelete = False
            ##doc.Delete(sp.Id)           #delete the shared parameter

TransactionManager.Instance.TransactionTaskDone()# End Transaction
OUT = results                           #return the results to Dyanmo environment

Parameter-Purge-Unused.dyn (15.5 KB)



Hi @Draxl_Andreas

you can try this version

import sys
import clr
import System
from System.Collections.Generic import List

import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

from Autodesk.Revit.UI import *

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

dialog = TaskDialog("Purge Project Parameters")

# Properties
dialog.MainInstruction = 'Unused Parameter Type to Delete'
dialog.FooterText = "Note: Only instance parameters will be processed"
# Add Command Link
                      'Delete all Parameters',
                      'Deleting all unused Parameters')
                      'Delete only Shared Parameters',
                      'Deleting Unused Shared Parameters (Only)')

diag = dialog.Show()

# Force close any open transactions to ensure a clean slate
# 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:
# Start a transaction to remove the parameter definitions			
t = Transaction(doc, "Remove Parameters")
for def_ in def_toRemove:
	if hasattr(def_, "Id"):
		filterbyId = System.Predicate[System.Object](lambda x : x.Id == def_.Id)
		# for all Parameters
		if diag == TaskDialogResult.CommandLink1:
			param_elem = List[DB.Element](FilteredElementCollector(doc).OfClass(ParameterElement).WhereElementIsNotElementType().ToElements()).Find(filterbyId)
		# for only SharedParameters
		elif diag == TaskDialogResult.CommandLink2:
			param_elem = List[DB.Element](FilteredElementCollector(doc).OfClass(SharedParameterElement).WhereElementIsNotElementType().ToElements()).Find(filterbyId)
			param_elem = None
		if param_elem is not None:
			result.append("Project Parameter '{}' removed".format(def_.Name))

OUT = result

my related article


@c.poupin ,

it should be a small issue ?

i use Revit 2024



see this see post

or try with IronPython(2 or 3)

you may encounter other bugs with Revit 2024 + CPython3 (there have been slight changes)

1 Like