Deletes a set of elements from the document.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Syntax
Visual Basic |
---|
Public Function Delete ( _
elementIds As ICollection(Of ElementId) _
) As ICollection(Of ElementId) |
Parameters
- elementIds
- Type: System.Collections.Generic..::..ICollection<(Of <(<'ElementId>)>)>
The ids of the elements to delete.
Return Value
The deleted element id set.
Remarks
Examples
CopyC#
ICollection<Autodesk.Revit.DB.ElementId> idSelection = null ;
UIDocument uidoc = new UIDocument(document);
ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
foreach (ElementId id in selectedIds)
{
idSelection.Add(id);
}
ICollection<Autodesk.Revit.DB.ElementId> deletedIdSet = document.Delete(idSelection);
if (0 == deletedIdSet.Count)
{
throw new Exception("Deleting the selected elements in Revit failed.");
}
TaskDialog.Show("Revit","The selected element has been removed.");
CopyC#
UIDocument uidoc = new UIDocument(document);
ICollection<ElementId> elements = uidoc.Selection.GetElementIds();
ICollection<Autodesk.Revit.DB.ElementId> deletedIdSet = document.Delete(elements);
if (0 == deletedIdSet.Count)
{
throw new Exception("Deleting the selected elements in Revit failed.");
}
TaskDialog.Show("Revit","The selected element has been removed.");
CopyVB.NET
Dim idSelection As ICollection(Of Autodesk.Revit.DB.ElementId) = Nothing
Dim uidoc As New UIDocument(document)
Dim selectedIds As ICollection(Of ElementId) = uidoc.Selection.GetElementIds()
For Each id As ElementId In selectedIds
idSelection.Add(id)
Next
Dim deletedIdSet As ICollection(Of Autodesk.Revit.DB.ElementId) = document.Delete(idSelection)
If 0 = deletedIdSet.Count Then
Throw New Exception("Deleting the selected elements in Revit failed.")
End If
TaskDialog.Show("Revit", "The selected element has been removed.")
CopyVB.NET
Dim uidoc As New UIDocument(document)
Dim elements As ICollection(Of ElementId) = uidoc.Selection.GetElementIds()
Dim deletedIdSet As ICollection(Of Autodesk.Revit.DB.ElementId) = document.Delete(elements)
If 0 = deletedIdSet.Count Then
Throw New Exception("Deleting the selected elements in Revit failed.")
End If
TaskDialog.Show("Revit", "The selected element has been removed.")
Exceptions
See Also