我们经常会添加自己的参数到对象中,一个参数可以添加到多个类别的对象。2011提供的过滤功能可以用参数的值来进行过滤。 下面代码可以对自定义参数按照参数值进行过滤。 using System; using System.Collections.Generic; using System.Text; //using System.Windows.Forms; using Autodesk.Revit .DB; using Autodesk.Revit.UI; using Autodesk.Revit .ApplicationServices; using Autodesk.Revit.Attributes ; [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)] [RegenerationAttribute(Autodesk.Revit.Attributes.RegenerationOption.Manual)] public class ParamFilterTest : IExternalCommand { public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; Wall wall = uidoc.Selection.PickObject( Autodesk.Revit.UI.Selection.ObjectType.Element) .Element as Wall; Parameter parameter = wall.get_Parameter( "MyShared"); ParameterValueProvider pvp = new ParameterValueProvider(parameter.Id); FilterStringEquals strEquals = new FilterStringEquals(); FilterStringRule sRule = new FilterStringRule(pvp, strEquals, "MyValue", true); ElementParameterFilter filter = new ElementParameterFilter(sRule); FilteredElementCollector collector = new FilteredElementCollector(doc); collector.WherePasses(filter); TaskDialog.Show("count", collector.ToElementIds().Count.ToString()); return Result.Succeeded; } }