Selection Filter can be found from the Revit Addins category of the Visual C# Project Items. After the wizard pages have been filled in like:
A new ISelectionFilter derivative will be created and its two core methods, AllowElement and AllowReference be implemented based on the settings of the Selection Filter wizard, such as what Element classes, which BuiltInCategory values, and what Reference.GeometryObject types to allow in the selection.
using System;
using System.Text;
using System.Xml;
using System.Linq;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Analysis;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;
using Autodesk.Revit.Collections;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;
using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;
namespace RevitAddinCSProject
{
public class SelectionFilter1 : ISelectionFilter
{
public bool AllowElement(Element elem)
{
if (elem is Wall) return true;
if (elem.Category.Id.IntegerValue == (int)BuiltInCategory.OST_WallsDefault) return true;
if (elem.Category.Id.IntegerValue == (int)BuiltInCategory.OST_WallsInsulation) return true;
if (elem.Category.Id.IntegerValue == (int)BuiltInCategory.OST_WallsStructure) return true;
return false;
}
public bool AllowReference(Reference refer, XYZ pos)
{
if (refer.GeometryObject == null) return false;
if (refer.GeometryObject is Edge) return true;
if (refer.GeometryObject is Face) return true;
return false;
}
}
}
With Selection Filter of RevitAddinWizard, an ISelectionFilter interface will be implemented in a moment and it can address all different Element classes, Category values, and/or Reference types, and even better, any combinations of them.
Links to some related articles:
Use RevitAddinWizard to Create IUpdater Derivatives of Revit API
Implement IFailuresPreprocessor of Revit API
Use RevitAddinWizard to Implement IFailuresPreprocessor of Revit API
Implement An IFailuresProcessor of Revit API
Use RevitAddinWizard to Implement IFailuresProcessor of Revit API
Command Availability And Revit Flavors/Categories of Revit API
Use RevitAddinWizard to Implement IExternalCommandavailability of Revit API
Implement ISelectionFilter of Revit API
Use RevitAddinWizard to Implement ISelectionFilter of Revit API
Recent Comments