/// <summary> /// Convert FilterRule to our custom FilterRuleBuilder which will be displayed in form controls /// </summary> /// <param name="param">Parameter to which the FilterRule is applied.</param> /// <param name="rule">FilterRule to be converted.</param> /// <returns>Custom FilterRuleBuilder data converted from FilterRule</returns> public static FilterRuleBuilder CreateFilterRuleBuilder(BuiltInParameter param, FilterRule rule) { // Maybe FilterRule is inverse rule, we need to find its inner rule(FilterValueRule) // Note that the rule may be inversed more than once. bool inverted = false; FilterRule innerRule = ReflectToInnerRule(rule, out inverted); if (innerRule is FilterStringRule) { FilterStringRule strRule = innerRule as FilterStringRule; FilterStringRuleEvaluator evaluator = strRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), strRule.RuleString, strRule.RuleString.ToLower() == strRule.RuleString ? false : true)); } else if (innerRule is FilterDoubleRule) { FilterDoubleRule dbRule = innerRule as FilterDoubleRule; FilterNumericRuleEvaluator evaluator = dbRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), dbRule.RuleValue, dbRule.Epsilon)); } else if (innerRule is FilterIntegerRule) { FilterIntegerRule intRule = innerRule as FilterIntegerRule; FilterNumericRuleEvaluator evaluator = intRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), intRule.RuleValue)); } else if (innerRule is FilterElementIdRule) { FilterElementIdRule idRule = innerRule as FilterElementIdRule; FilterNumericRuleEvaluator evaluator = idRule.GetEvaluator(); return(new FilterRuleBuilder(param, GetEvaluatorCriteriaName(evaluator, inverted), idRule.RuleValue)); } // // for other rule, not supported yet throw new System.NotImplementedException("The filter rule is not recognizable and supported yet!"); }
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document document = commandData.Application.ActiveUIDocument.Document; UIDocument uidoc = commandData.Application.ActiveUIDocument; ICollection <ElementId> ids = uidoc.Selection.GetElementIds(); string prompt = ""; BuiltInParameter volParam = BuiltInParameter.HOST_VOLUME_COMPUTED; // provider ParameterValueProvider pvp = new ParameterValueProvider(new ElementId((int)volParam)); // evaluator FilterNumericRuleEvaluator fnrv = new FilterNumericGreater(); // 篩選面體積大於500立方呎的元件 double ruleValue = 500f; // rule 規則 FilterRule fRule = new FilterDoubleRule(pvp, fnrv, ruleValue, 1E-6); // Create an ElementParameter filter 創建ElementParameter篩選器 ElementParameterFilter filter = new ElementParameterFilter(fRule); // Apply the filter to the elements in the active document 使用這個篩選器到作用文件檔案中的元件 FilteredElementCollector collector = new FilteredElementCollector(document); IList <Element> elems = collector.WherePasses(filter).ToElements(); prompt += "篩選後的元件數量:" + elems.Count.ToString() + "\n"; ElementCategoryFilter filterWall = new ElementCategoryFilter(BuiltInCategory.OST_Walls); IList <Element> walls = collector.WherePasses(filter).WherePasses(filterWall).ToElements(); prompt += "篩選後的牆數量:" + walls.Count.ToString() + "\n"; TaskDialog.Show("篩選", prompt); return(Autodesk.Revit.UI.Result.Succeeded); }
/// <summary> /// Optional - example of parameter filter. /// Find walls whose length is longer than a certain length. e.g., 60 feet /// wall.parameter(length) > 60 feet /// This could get more complex than looping through in terms of writing a code. /// See page 87 of Developer guide. /// </summary> public IList <Element> FindLongWalls() { // Constant for this function. const double kWallLength = 60.0; // 60 feet. hard coding for simplicity. // First, narrow down to the elements of the given type and category var collector = new FilteredElementCollector(_doc).OfClass(typeof(Wall)); // Define a filter by parameter // 1st arg - value provider BuiltInParameter lengthParam = BuiltInParameter.CURVE_ELEM_LENGTH; int iLengthParam = (int)lengthParam; var paramValueProvider = new ParameterValueProvider(new ElementId(iLengthParam)); // 2nd - evaluator FilterNumericGreater evaluator = new FilterNumericGreater(); // 3rd - rule value double ruleVal = kWallLength; // 4th - epsilon const double eps = 1E-06; // Define a rule var filterRule = new FilterDoubleRule(paramValueProvider, evaluator, ruleVal, eps); // Create a new filter var paramFilter = new ElementParameterFilter(filterRule); // Go through the filter IList <Element> elems = collector.WherePasses(paramFilter).ToElements(); return(elems); }
public IList <Element> GetElementValueDouble(RevitParameter valRevitParameter, List <ElementId> valCategoryElementId, string valValue) { IList <Element> vResult = new List <Element>(); foreach (var vCategoryId in valCategoryElementId) { BuiltInCategory vBuiltInCategory = (BuiltInCategory)vCategoryId.IntegerValue; ParameterValueProvider vPovider = new ParameterValueProvider(valRevitParameter.ElementId); string vRulestring = valValue; FilteredElementCollector vCollector = new FilteredElementCollector(_Doc); vCollector.OfCategory(vBuiltInCategory); LibNumeric insLibNumeric = new LibNumeric(); double ruleValDb = 0.0; if (insLibNumeric.IsDouble(valValue)) { Double vNum = 0; Double.TryParse(valValue, out vNum); ruleValDb = vNum; } ParameterValueProvider pvp = new ParameterValueProvider(valRevitParameter.ElementId); FilterNumericEquals fnrv = new FilterNumericEquals(); var vFilterDoubleRule = new FilterDoubleRule(pvp, fnrv, ruleValDb, 10e-10); var epf = new ElementParameterFilter(vFilterDoubleRule); vCollector.WherePasses(epf); IList <Element> vElements = vCollector.ToElements(); if (vElements != null) { if (vElements.Count > 0) { vResult = vElements.Concat(vElements).ToList(); } } } return(vResult); }
public static FilteredElementCollector GetElementsByShareParamValue(Document doc, BuiltInCategory bic, string sParaName, double dValue) { SharedParameterElement para = (from p in new FilteredElementCollector(doc) .OfClass(typeof(SharedParameterElement)) .Cast <SharedParameterElement>() where p.Name.Equals(sParaName) select p).First(); ParameterValueProvider provider = new ParameterValueProvider(para.Id); FilterNumericRuleEvaluator evaluator = new FilterNumericEquals(); double sLength_feet = UnitUtils.Convert( dValue, DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_DECIMAL_FEET); double epsilon = 0.0001; FilterRule rule = new FilterDoubleRule( provider, evaluator, sLength_feet, epsilon); ElementParameterFilter filter = new ElementParameterFilter(rule); FilteredElementCollector collector = new FilteredElementCollector(doc) .OfCategory(bic) .WherePasses(filter); return(collector); }
/// <summary> /// ElementParameterFilter参数过滤器 Creates an ElementParameter filter to find rooms whose area is greater than specified value /// </summary> /// <remarks>提示: 参数过滤条件可能比其他的类型过滤条件要快,但是这要视条件而定。毕竟这是一个慢过,使用时请按照过滤标准的复杂程度而异。</remarks> public void ElementParameterFilter_FindRooms(Document Document) { // 以下5个步骤演示了要进行参数过滤的完整过程。 // provider ParameterValueProvider pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.ROOM_AREA)); // evaluator FilterNumericRuleEvaluator fnrv = new FilterNumericGreater(); // 过滤规则 : 参数“房间面积”的值“大于”“100 Square Foot”。(浮点数比较的容差为0.000001) FilterRule fRule = new FilterDoubleRule(pvp, fnrv, 100, 0.000001); // Create an ElementParameter filter ElementParameterFilter filter = new ElementParameterFilter(fRule); // Apply the filter to the elements in the active document FilteredElementCollector collector = new FilteredElementCollector(Document); IList <Element> rooms = collector.WherePasses(filter).ToElements(); // 反转过滤条件 // Find rooms whose area is less than or equal to 100: // Use inverted filter to match elements ElementParameterFilter lessOrEqualFilter = new ElementParameterFilter(fRule, true); collector = new FilteredElementCollector(Document); IList <Element> lessOrEqualFounds = collector.WherePasses(lessOrEqualFilter).ToElements(); }
/// <summary> /// Optional - example of parameter filter. /// Find walls whose length is longer than a certain length. e.g., 60 feet /// wall.parameter(length) > 60 feet /// This could get more complex than looping through in terms of writing a code. /// See page 87 of Developer guide. /// </summary> public IList<Element> FindLongWalls() { // Constant for this function. const double kWallLength = 60.0; // 60 feet. hard coding for simplicity. // First, narrow down to the elements of the given type and category var collector = new FilteredElementCollector(_doc).OfClass(typeof(Wall)); // Define a filter by parameter // 1st arg - value provider BuiltInParameter lengthParam = BuiltInParameter.CURVE_ELEM_LENGTH; int iLengthParam = (int)lengthParam; var paramValueProvider = new ParameterValueProvider(new ElementId(iLengthParam)); // 2nd - evaluator FilterNumericGreater evaluator = new FilterNumericGreater(); // 3rd - rule value double ruleVal = kWallLength; // 4th - epsilon const double eps = 1E-06; // Define a rule var filterRule = new FilterDoubleRule(paramValueProvider, evaluator, ruleVal, eps); // Create a new filter var paramFilter = new ElementParameterFilter(filterRule); // Go through the filter IList<Element> elems = collector.WherePasses(paramFilter).ToElements(); return elems; }
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; Reference r = uidoc.Selection.PickObject( ObjectType.Element ); // 'Autodesk.Revit.DB.Reference.Element' is // obsolete: Property will be removed. Use // Document.GetElement(Reference) instead. //Wall wall = r.Element as Wall; // 2011 Wall wall = doc.GetElement( r ) as Wall; // 2012 //Parameter parameter = wall.get_Parameter( "Unconnected Height" ); // 2014, causes warning CS0618: 'Autodesk.Revit.DB.Element.get_Parameter(string)' is obsolete: 'This property is obsolete in Revit 2015, as more than one parameter can have the same name on a given element. Use Element.Parameters to obtain a complete list of parameters on this Element, or Element.GetParameters(String) to get a list of all parameters by name, or Element.LookupParameter(String) to return the first available parameter with the given name.' Parameter parameter = wall.get_Parameter( BuiltInParameter.WALL_USER_HEIGHT_PARAM ); // 2015, avoids warning, in language indepependent and more effective to look up ParameterValueProvider pvp = new ParameterValueProvider( parameter.Id ); FilterNumericRuleEvaluator fnrv = new FilterNumericGreater(); FilterRule fRule = new FilterDoubleRule( pvp, fnrv, 20, 1E-6 ); ElementParameterFilter filter = new ElementParameterFilter( fRule ); FilteredElementCollector collector = new FilteredElementCollector( doc ); // Find walls with unconnected height // less than or equal to 20: ElementParameterFilter lessOrEqualFilter = new ElementParameterFilter( fRule, true ); IList<Element> lessOrEqualFounds = collector.WherePasses( lessOrEqualFilter ) .OfCategory( BuiltInCategory.OST_Walls ) .OfClass( typeof( Wall ) ) .ToElements(); TaskDialog.Show( "Revit", "Walls found: " + lessOrEqualFounds.Count ); return Result.Succeeded; }
void f4( Document doc ) { // Use numeric evaluator and integer rule to test ElementId parameter // Filter levels whose id is greater than specified id value BuiltInParameter testParam = BuiltInParameter.ID_PARAM; ParameterValueProvider pvp = new ParameterValueProvider( new ElementId( (int) testParam ) ); FilterNumericRuleEvaluator fnrv = new FilterNumericGreater(); // filter elements whose Id is greater than 99 ElementId ruleValId = new ElementId( 99 ); FilterRule paramFr = new FilterElementIdRule( pvp, fnrv, ruleValId ); ElementParameterFilter epf = new ElementParameterFilter( paramFr ); FilteredElementCollector collector = new FilteredElementCollector( doc ); collector.OfClass( typeof( ViewPlan ) ) .WherePasses( epf ); // only deal with ViewPlan // Use numeric evaluator and integer rule to test bool parameter // Filter levels whose crop view is false int ruleValInt = 0; testParam = BuiltInParameter.VIEWER_CROP_REGION; pvp = new ParameterValueProvider( new ElementId( (int) testParam ) ); fnrv = new FilterNumericEquals(); paramFr = new FilterIntegerRule( pvp, fnrv, ruleValInt ); epf = new ElementParameterFilter( paramFr ); collector = new FilteredElementCollector( doc ); collector.OfClass( typeof( ViewPlan ) ) .WherePasses( epf ); // only deal with ViewPlan // Use numeric evaluator and double rule to test double parameter // Filter levels whose top offset is greater than specified value double ruleValDb = 10; testParam = BuiltInParameter.VIEWER_BOUND_OFFSET_TOP; pvp = new ParameterValueProvider( new ElementId( (int) testParam ) ); fnrv = new FilterNumericGreater(); paramFr = new FilterDoubleRule( pvp, fnrv, ruleValDb, double.Epsilon ); collector = new FilteredElementCollector( doc ); collector.OfClass( typeof( ViewPlan ) ) .WherePasses( epf ); // only deal with ViewPlan // Use string evaluator and string rule to test string parameter // Filter all elements whose view name contains level String ruleValStr = "Level"; testParam = BuiltInParameter.VIEW_NAME; pvp = new ParameterValueProvider( new ElementId( (int) testParam ) ); FilterStringRuleEvaluator fnrvStr = new FilterStringContains(); paramFr = new FilterStringRule( pvp, fnrvStr, ruleValStr, false ); collector = new FilteredElementCollector( doc ); collector.OfClass( typeof( ViewPlan ) ) .WherePasses( epf ); // only deal with ViewPlan }
protected override void SolveInstance(IGH_DataAccess DA) { var parameterId = ElementId.InvalidElementId; if (!DA.GetData("ParameterKey", ref parameterId)) { return; } DA.DisableGapLogic(); if (!TryGetParameterDefinition(Revit.ActiveDBDocument, parameterId, out var storageType, out var parameterType)) { if (parameterId.TryGetBuiltInParameter(out var builtInParameter)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Failed to found parameter '{LabelUtils.GetLabelFor(builtInParameter)}' in Revit document."); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Failed to found parameter '{parameterId.IntegerValue}' in Revit document."); } return; } var provider = new ParameterValueProvider(parameterId); Autodesk.Revit.DB.FilterRule rule = null; if (storageType == StorageType.String) { FilterStringRuleEvaluator ruleEvaluator = null; switch (Condition) { case ConditionType.NotEquals: case ConditionType.Equals: ruleEvaluator = new FilterStringEquals(); break; case ConditionType.Greater: ruleEvaluator = new FilterStringGreater(); break; case ConditionType.GreaterOrEqual: ruleEvaluator = new FilterStringGreaterOrEqual(); break; case ConditionType.Less: ruleEvaluator = new FilterStringLess(); break; case ConditionType.LessOrEqual: ruleEvaluator = new FilterStringLessOrEqual(); break; } var goo = default(GH_String); if (DA.GetData("Value", ref goo)) { rule = new FilterStringRule(provider, ruleEvaluator, goo.Value, true); } } else { FilterNumericRuleEvaluator ruleEvaluator = null; switch (Condition) { case ConditionType.NotEquals: case ConditionType.Equals: ruleEvaluator = new FilterNumericEquals(); break; case ConditionType.Greater: ruleEvaluator = new FilterNumericGreater(); break; case ConditionType.GreaterOrEqual: ruleEvaluator = new FilterNumericGreaterOrEqual(); break; case ConditionType.Less: ruleEvaluator = new FilterNumericLess(); break; case ConditionType.LessOrEqual: ruleEvaluator = new FilterNumericLessOrEqual(); break; } switch (storageType) { case StorageType.Integer: { var goo = default(GH_Integer); if (DA.GetData("Value", ref goo)) { rule = new FilterIntegerRule(provider, ruleEvaluator, goo.Value); } } break; case StorageType.Double: { var goo = default(GH_Number); if (DA.GetData("Value", ref goo)) { if (Condition == ConditionType.Equals || Condition == ConditionType.NotEquals) { if (parameterType == ParameterType.Length || parameterType == ParameterType.Area || parameterType == ParameterType.Volume) { rule = new FilterDoubleRule(provider, ruleEvaluator, ToHost(goo.Value, parameterType), ToHost(Revit.VertexTolerance, parameterType)); } else { rule = new FilterDoubleRule(provider, ruleEvaluator, ToHost(goo.Value, parameterType), 1e-6); } } else { rule = new FilterDoubleRule(provider, ruleEvaluator, ToHost(goo.Value, parameterType), 0.0); } } } break; case StorageType.ElementId: { switch (parameterType) { case (ParameterType)int.MaxValue: // Category { var value = default(Types.Category); if (DA.GetData("Value", ref value)) { rule = new FilterElementIdRule(provider, ruleEvaluator, value); } } break; case ParameterType.FamilyType: { var value = default(Types.ElementType); if (DA.GetData("Value", ref value)) { rule = new FilterElementIdRule(provider, ruleEvaluator, value); } } break; default: { var value = default(Types.Element); if (DA.GetData("Value", ref value)) { rule = new FilterElementIdRule(provider, ruleEvaluator, value); } } break; } } break; } } if (rule is object) { if (Condition == ConditionType.NotEquals) { DA.SetData("Rule", new FilterInverseRule(rule)); } else { DA.SetData("Rule", rule); } } }
public static ElementFilter createParameterFilter(Document doc, ParameterData parameter, string operation, string ruleString) { ElementId parameterId = parameter.Id; ParameterValueProvider fvp = new ParameterValueProvider(parameterId); StorageType storageType = parameter.StorageType; FilterRule fRule = null; FilterInverseRule fInvRule = null; ElementParameterFilter filter = null; switch (storageType) { case StorageType.String: case StorageType.Integer: FilterStringRuleEvaluator fsre = null; switch (operation) { case "равно": fsre = new FilterStringEquals(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); filter = new ElementParameterFilter(fRule); break; case "не равно": fsre = new FilterStringEquals(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; case "содержит": fsre = new FilterStringContains(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); filter = new ElementParameterFilter(fRule); break; case "не содержит": fsre = new FilterStringContains(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; case "начинается с": fsre = new FilterStringBeginsWith(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); filter = new ElementParameterFilter(fRule); break; case "не начинается с": fsre = new FilterStringBeginsWith(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; case "заканчивается на": fsre = new FilterStringEndsWith(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); filter = new ElementParameterFilter(fRule); break; case "не заканчивается на": fsre = new FilterStringEndsWith(); fRule = new FilterStringRule(fvp, fsre, ruleString, true); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; } break; case StorageType.Double: FilterNumericRuleEvaluator fnre = null; double ruleValue = Convert.ToDouble(ruleString); switch (operation) { case "равно": fnre = new FilterNumericEquals(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); filter = new ElementParameterFilter(fRule); break; case "не равно": fnre = new FilterNumericEquals(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; case "больше": fnre = new FilterNumericGreater(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); filter = new ElementParameterFilter(fRule); break; case "больше или равно": fnre = new FilterNumericGreaterOrEqual(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); filter = new ElementParameterFilter(fRule); break; case "меньше": fnre = new FilterNumericLess(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); filter = new ElementParameterFilter(fRule); break; case "меньше или равно": fnre = new FilterNumericLessOrEqual(); fRule = new FilterDoubleRule(fvp, fnre, ruleValue, 0.0); filter = new ElementParameterFilter(fRule); break; } break; case StorageType.ElementId: var levels = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).ToElements(); var level = levels.Where(i => i.Name == ruleString).FirstOrDefault(); ElementId ruleId = level.Id; fnre = null; switch (operation) { case "равно": fnre = new FilterNumericEquals(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); filter = new ElementParameterFilter(fRule); break; case "не равно": fnre = new FilterNumericEquals(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); fInvRule = new FilterInverseRule(fRule); filter = new ElementParameterFilter(fInvRule); break; case "выше": fnre = new FilterNumericGreater(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); filter = new ElementParameterFilter(fRule); break; case "ровно или выше": fnre = new FilterNumericGreaterOrEqual(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); filter = new ElementParameterFilter(fRule); break; case "ниже": fnre = new FilterNumericLess(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); filter = new ElementParameterFilter(fRule); break; case "ровно или ниже": fnre = new FilterNumericLessOrEqual(); fRule = new FilterElementIdRule(fvp, fnre, ruleId); filter = new ElementParameterFilter(fRule); break; } break; } return(filter); }
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; Reference r = uidoc.Selection.PickObject( ObjectType.Element ); // 'Autodesk.Revit.DB.Reference.Element' is // obsolete: Property will be removed. Use // Document.GetElement(Reference) instead. //Wall wall = r.Element as Wall; // 2011 Wall wall = doc.GetElement( r ) as Wall; // 2012 Parameter parameter = wall.get_Parameter( "Unconnected Height" ); ParameterValueProvider pvp = new ParameterValueProvider( parameter.Id ); FilterNumericRuleEvaluator fnrv = new FilterNumericGreater(); FilterRule fRule = new FilterDoubleRule( pvp, fnrv, 20, 1E-6 ); ElementParameterFilter filter = new ElementParameterFilter( fRule ); FilteredElementCollector collector = new FilteredElementCollector( doc ); // Find walls with unconnected height // less than or equal to 20: ElementParameterFilter lessOrEqualFilter = new ElementParameterFilter( fRule, true ); IList<Element> lessOrEqualFounds = collector.WherePasses( lessOrEqualFilter ) .OfCategory( BuiltInCategory.OST_Walls ) .OfClass( typeof( Wall ) ) .ToElements(); TaskDialog.Show( "Revit", "Walls found: " + lessOrEqualFounds.Count ); return Result.Succeeded; }
private ElementFilter CreateParamFilter(int paramId, string strOperator, string paramValue, bool emptyValue) { try { ParameterProperties pp = selectedParameters[paramId]; ParameterValueProvider pvp = new ParameterValueProvider(new ElementId(pp.ParamId)); switch (pp.ParamStorageType) { case StorageType.ElementId: if (pp.ParamName == "Phase Created" || pp.ParamName == "Phase Demolished") { FilterNumericRuleEvaluator fnre1 = new FilterNumericEquals(); var phaseId = from phase in phases where phase.Value.Name == paramValue select phase.Key; int pId = phaseId.First(); ElementId ruleValId = new ElementId(pId); FilterRule filterRule1 = new FilterElementIdRule(pvp, fnre1, ruleValId); if (strOperator == "does not equal") { return(new ElementParameterFilter(filterRule1, true)); } else { return(new ElementParameterFilter(filterRule1)); } } return(null); case StorageType.Double: if (emptyValue) { FilterNumericRuleEvaluator fnre = new FilterNumericGreater(); FilterDoubleRule doubleRule = new FilterDoubleRule(pvp, fnre, 0, double.Epsilon); return(new ElementParameterFilter(doubleRule, true)); } FilterNumericRuleEvaluator fnre2 = FindFilterNumericRuleEvaluator(strOperator); double dblValue = 0; if (!string.IsNullOrEmpty(paramValue)) { double.TryParse(paramValue, out dblValue); } FilterRule filterRule2 = new FilterDoubleRule(pvp, fnre2, dblValue, double.Epsilon); if (strOperator == "does not equal") { return(new ElementParameterFilter(filterRule2, true)); } else { return(new ElementParameterFilter(filterRule2)); } case StorageType.Integer: if (emptyValue) { FilterNumericRuleEvaluator fnre = new FilterNumericGreater(); FilterIntegerRule integerRule = new FilterIntegerRule(pvp, fnre, 0); return(new ElementParameterFilter(integerRule, true)); } FilterNumericRuleEvaluator fnre3 = FindFilterNumericRuleEvaluator(strOperator); int intValue = 0; if (pp.ParamName == "Workset") { var worksetId = from ws in worksets where ws.Value.Name == paramValue select ws.Key; intValue = worksetId.First(); } else if (!string.IsNullOrEmpty(paramValue)) { int.TryParse(paramValue, out intValue); } FilterRule filterRule3 = new FilterIntegerRule(pvp, fnre3, intValue); if (strOperator == "does not equal") { return(new ElementParameterFilter(filterRule3, true)); } else { return(new ElementParameterFilter(filterRule3)); } case StorageType.String: if (emptyValue) { FilterStringRuleEvaluator fsre = new FilterStringGreater(); FilterStringRule stringRule = new FilterStringRule(pvp, fsre, "", false); return(new ElementParameterFilter(stringRule, true)); } FilterStringRuleEvaluator fnre4 = FindFilterStringRuleEvaluator(strOperator); string strValue = paramValue; FilterStringRule filterRule4 = new FilterStringRule(pvp, fnre4, strValue, false); if (strOperator.Contains("does not")) { return(new ElementParameterFilter(filterRule4, true)); } else { return(new ElementParameterFilter(filterRule4, false)); } default: return(null); } } catch (Exception ex) { MessageBox.Show("Failed to create parameter filters.\n" + ex.Message, "CreateParamFilter", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(null); }