public IList <Element> GetElementValueDoubleLessOrEqual(RevitParameter valRevitParameter, List <ElementId> valCategoryElementId, string valValue, string valValueToString) { IList <Element> vResult = new List <Element>(); IList <Element> vResultTemp = 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 + 0.001; } ParameterValueProvider pvp = new ParameterValueProvider(valRevitParameter.ElementId); FilterNumericLessOrEqual fnrv = new FilterNumericLessOrEqual(); 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) { vResultTemp = vElements.Concat(vElements).ToList(); } } } vResult = GetElementValueToString(valRevitParameter, vResultTemp, valValueToString, valValue); return(vResult); }
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); }