Namespace: Autodesk.Revit.UI.Selection
Assembly: RevitAPIUI (in RevitAPIUI.dll) Version: 24.0.0.0 (24.0.0.0)
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- objectType
- Type: Autodesk.Revit.UI.SelectionObjectType
Specifies the type of object to be selected.
- selectionFilter
- Type: Autodesk.Revit.UI.SelectionISelectionFilter
The selection filter.
- statusPrompt
- Type: SystemString
The message shown on the status bar.
Return Value
A collection of references selected by the user.
Note: if the user cancels the operation (for example, through ESC), the method will throw an OperationCanceledException instance.
Remarks
The user will be shown "Finish" and "Cancel" buttons on the dialog bar to complete the selection operation. Uncheck the "Multiple" check-box to select single object and it will return the selected object directly.
Revit users will be permitted to manipulate the Revit view (zooming, panning, and rotating the view), but will not be permitted to click other items in the Revit user interface. Users are not permitted to switch the active view, close the active document or Revit application in the pick session, otherwise an exception will be thrown.
The selection will not be automatically added to the active selection buffer.
Note: this method must not be called during dynamic update, otherwise ForbiddenForDynamicUpdateException will be thrown.
Examples

public void SelectPlanarFaces(Autodesk.Revit.DB.Document document)
{
UIDocument uidoc = new UIDocument(document);
ISelectionFilter selFilter = new PlanarFacesSelectionFilter(document);
IList<Reference> faces = uidoc.Selection.PickObjects(ObjectType.Face, selFilter, "Select multiple planar faces");
}
public class PlanarFacesSelectionFilter : ISelectionFilter
{
Document doc = null;
public PlanarFacesSelectionFilter(Document document)
{
doc = document;
}
public bool AllowElement(Element element)
{
return true;
}
public bool AllowReference(Reference refer, XYZ point)
{
if (doc.GetElement(refer).GetGeometryObjectFromReference(refer) is PlanarFace)
{
return true; // Only return true for planar faces. Non-planar faces will not be selectable
}
return false;
}
}

Public Sub SelectPlanarFaces(document As Autodesk.Revit.DB.Document)
Dim uidoc As New UIDocument(document)
Dim selFilter As ISelectionFilter = New PlanarFacesSelectionFilter(document)
Dim faces As IList(Of Reference) = uidoc.Selection.PickObjects(ObjectType.Face, selFilter, "Select multiple planar faces")
End Sub
Public Class PlanarFacesSelectionFilter
Implements ISelectionFilter
Private doc As Document = Nothing
Public Sub New(document As Document)
doc = document
End Sub
Public Function AllowElement(element As Element) As Boolean Implements ISelectionFilter.AllowElement
Return True
End Function
Public Function AllowReference(refer As Reference, point As XYZ) As Boolean Implements ISelectionFilter.AllowReference
If TypeOf doc.GetElement(refer).GetGeometryObjectFromReference(refer) Is PlanarFace Then
' Only return true for planar faces. Non-planar faces will not be selectable
Return True
End If
Return False
End Function
End Class
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.ExceptionsArgumentOutOfRangeException | Thrown when the objectType is not a recognized value. |
Autodesk.Revit.ExceptionsArgumentNullException | Thrown when the selectionFilter is a null reference (Nothing in Visual Basic) or statusPrompt is a null reference (Nothing in Visual Basic). |
Autodesk.Revit.ExceptionsOperationCanceledException | Thrown when the Revit user cancelled this operation. Thrown when the Revit user tried to switch the active view, close the active document or Revit application when responding to this mode. |
Autodesk.Revit.ExceptionsForbiddenForDynamicUpdateException | Thrown if this method is called during dynamic update. |