Share

Document.GetAllUnusedElements Method

Returns the list of element ids that are not used. The list of unused element ids may include elements that can't be deleted.


Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 26.1.0.0 (26.1.0.34)

Syntax

C#

public ISet<ElementId> GetAllUnusedElements(
	ISet<ElementId> categories
)

Parameters

categories  ISet<ElementId>
Collection of categories to check for unused elements.

Return Value

ISet<ElementId>
Unused element ids.

Exceptions

ExceptionCondition
ArgumentNullException A non-optional argument was null

Remarks

This method returns unused element ids that are available in the Purge Unused window in the Revit, including elements that can't be deleted. To get unused elements that do not have a category assigned add INVALID to the collection of categories. If the input categories collection is empty, the method returns all unused elements in the document.

Example

C#

public void GetAllUnusedElements(Autodesk.Revit.DB.Document document)
{
   // Get all unused elements in the document
   var allUnusedElementIds = document.GetAllUnusedElements(new HashSet<ElementId>());

   // Get unused elements without a category
   var unusedElementIdsWithNoCategory = document.GetAllUnusedElements(new HashSet<ElementId>() { new ElementId(BuiltInCategory.INVALID) });

   // Get unused wall and floors types
   HashSet<ElementId> categoriesToPurge = new HashSet<ElementId>
   {
      new ElementId(BuiltInCategory.OST_Walls),
      new ElementId(BuiltInCategory.OST_Floors)
   };

   var unusedElementIds = document.GetAllUnusedElements(categoriesToPurge);
}

VB

     Public Sub GetAllUnusedElements(ByVal document As Document)
         ' Get all unused elements in the document
         Dim allUnusedElementIds = document.GetAllUnusedElements(New HashSet(Of ElementId)())

         ' Get unused elements without a category
         Dim unusedElementIdsWithNoCategory = document.GetAllUnusedElements(New HashSet(Of ElementId)() From {
                New ElementId(BuiltInCategory.INVALID)
            })

         ' Get unused wall and floors types
         Dim categoriesToPurge As HashSet(Of ElementId) = New HashSet(Of ElementId) From {
   New ElementId(BuiltInCategory.OST_Walls),
   New ElementId(BuiltInCategory.OST_Floors)
}

         Dim unusedElementIds = document.GetAllUnusedElements(categoriesToPurge)
     End Sub

See Also

Reference

Was this information helpful?