public static List <Autodesk.Revit.DB.FilterRule> ConverToRevitFilterRule(List <FilterRule> filterRules) { List <Autodesk.Revit.DB.FilterRule> revitFilterRules = new List <Autodesk.Revit.DB.FilterRule>(); try { foreach (FilterRule rule in filterRules) { ElementId paramId = new ElementId(rule.ParameterId); Autodesk.Revit.DB.FilterRule revitFilterRule = null; switch (rule.ParameterStorageType) { case ParameterStorageType.Double: double dblValue = 0; if (double.TryParse(rule.RuleValue, out dblValue)) { revitFilterRule = GetDoubleRule(paramId, rule.CriteriaName, dblValue); } break; case ParameterStorageType.Integer: int intValue = 0; if (int.TryParse(rule.RuleValue, out intValue)) { revitFilterRule = GetIntegerRule(paramId, rule.CriteriaName, intValue); } break; case ParameterStorageType.String: revitFilterRule = GetStringRule(paramId, rule.CriteriaName, rule.RuleValue); break; case ParameterStorageType.ElementId: int eId = 0; if (int.TryParse(rule.RuleValue, out eId)) { ElementId elementId = new ElementId(eId); revitFilterRule = GetElementIdRule(paramId, rule.CriteriaName, elementId); } break; } if (null != revitFilterRule) { revitFilterRules.Add(revitFilterRule); } } } catch (Exception ex) { System.Windows.MessageBox.Show("Failed to get Revit filter rules.\n" + ex.Message, "Get Revit Filter Rules", MessageBoxButton.OK, MessageBoxImage.Warning); } return(revitFilterRules); }
public static Autodesk.Revit.DB.FilterRule GetElementIdRule(ElementId paramId, CriteriaName selectedCriteria, ElementId ruleValue) { Autodesk.Revit.DB.FilterRule rule = null; try { switch (selectedCriteria) { case CriteriaName.equals: rule = ParameterFilterRuleFactory.CreateEqualsRule(paramId, ruleValue); break; case CriteriaName.isgreaterthan: rule = ParameterFilterRuleFactory.CreateGreaterRule(paramId, ruleValue); break; case CriteriaName.isgreaterthanorequalto: rule = ParameterFilterRuleFactory.CreateGreaterOrEqualRule(paramId, ruleValue); break; case CriteriaName.islessthan: rule = ParameterFilterRuleFactory.CreateLessRule(paramId, ruleValue); break; case CriteriaName.islessthanorequalto: rule = ParameterFilterRuleFactory.CreateLessOrEqualRule(paramId, ruleValue); break; case CriteriaName.doesnotequal: rule = ParameterFilterRuleFactory.CreateNotEqualsRule(paramId, ruleValue); break; } } catch (Exception ex) { System.Windows.MessageBox.Show("Failed to get integer filter rule.\n" + ex.Message, "Get Integer Filter Rule", MessageBoxButton.OK, MessageBoxImage.Warning); } return(rule); }
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 Autodesk.Revit.DB.FilterRule GetStringRule(ElementId paramId, CriteriaName selectedCriteria, string ruleValue) { Autodesk.Revit.DB.FilterRule rule = null; try { switch (selectedCriteria) { case CriteriaName.beginswith: rule = ParameterFilterRuleFactory.CreateBeginsWithRule(paramId, ruleValue, false); break; case CriteriaName.contains: rule = ParameterFilterRuleFactory.CreateContainsRule(paramId, ruleValue, false); break; case CriteriaName.endswith: rule = ParameterFilterRuleFactory.CreateEndsWithRule(paramId, ruleValue, false); break; case CriteriaName.equals: rule = ParameterFilterRuleFactory.CreateEqualsRule(paramId, ruleValue, false); break; case CriteriaName.isgreaterthan: rule = ParameterFilterRuleFactory.CreateGreaterRule(paramId, ruleValue, false); break; case CriteriaName.isgreaterthanorequalto: rule = ParameterFilterRuleFactory.CreateGreaterOrEqualRule(paramId, ruleValue, false); break; case CriteriaName.islessthan: rule = ParameterFilterRuleFactory.CreateLessRule(paramId, ruleValue, false); break; case CriteriaName.islessthanorequalto: rule = ParameterFilterRuleFactory.CreateLessOrEqualRule(paramId, ruleValue, false); break; case CriteriaName.doesnotbeginwith: rule = ParameterFilterRuleFactory.CreateNotBeginsWithRule(paramId, ruleValue, false); break; case CriteriaName.doesnotcontain: rule = ParameterFilterRuleFactory.CreateNotContainsRule(paramId, ruleValue, false); break; case CriteriaName.doesnotendwith: rule = ParameterFilterRuleFactory.CreateNotEndsWithRule(paramId, ruleValue, false); break; case CriteriaName.doesnotequal: rule = ParameterFilterRuleFactory.CreateNotEqualsRule(paramId, ruleValue, false); break; } } catch (Exception ex) { System.Windows.MessageBox.Show("Failed to get string filter rule.\n" + ex.Message, "Get String Filter Rule", MessageBoxButton.OK, MessageBoxImage.Warning); } return(rule); }
/// <summary> /// Reference to the Element /// </summary> /// <param name="internalFilterRule"></param> internal FilterRule(Autodesk.Revit.DB.FilterRule internalFilterRule) { this.InternalFilterRule = internalFilterRule; }