© 2010 Autodesk
Introduction to Revit 2011 API
User Selection
Selection Filter
§
§ISelection Interface to help filter objects during selection
§AllowElement()
§AllowReference()
§
§
§
§
public void SelectPlanarFaces(Autodesk.Revit.DB.Document document)
{
UIDocument uidoc = new UIDocument(document);
ISelectionFilter selFilter = new PlanarFacesSelectionFilter();
IList<Reference> faces = uidoc.Selection.PickObjects(ObjectType.Face, selFilter, "Select multiple planar faces");
}
public class PlanarFacesSelectionFilter : ISelectionFilter
{
        public bool AllowElement(Element element)
        {
         return true;
        }
        public bool AllowReference(Reference refer, XYZ point)
        {
          if (refer.GeometryObject is PlanarFace)  { return true;   }
return false;
         }
}
The user selection API allows API users to filter objects during the selection. The element or object selection – single and multiple selection methods, all have overloads that take an ISelectionFilter as a parameter. And it is this ISelectionFilter interface that enables the filtration of objects during a selection operation. It has two methods that can be overridden: AllowElement() which is used to specify if an element is allowed to be selected, and AllowReference() which is used to specify if a reference to a piece of geometry is allowed to be selected.

The code snippet included in the slide demonstrates the use of ISelectionFilter to allow selection of planar faces only.