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