コード例 #1
0
        protected static bool TryGetFilterLengthParam(DB.BuiltInParameter paramId, double pattern, out DB.ElementFilter filter)
        {
            var rule = new DB.FilterDoubleRule
                       (
                new DB.ParameterValueProvider(new DB.ElementId(paramId)),
                new DB.FilterNumericEquals(),
                pattern,
                Revit.VertexTolerance
                       );

            filter = new DB.ElementParameterFilter(rule, false);
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Creates a ElementFilter that passes elements with a number based parameter that match the provided FilterNumericRuleEvaluator.  The filter should then be passed to a Collector node and the Collector retrieves elements that pass the filter.
        /// </summary>
        /// <param name="parameterId">The ElementId as an int of the parameter to search.</param>
        /// <param name="value">Value of the parameter to search for.</param>
        /// <param name="tolerance">Tolerance on how close tot he value a match should be.</param>
        /// <param name="filterNumberRule">Revit FilterNumberRuleEvaluator that determines how to search the parameter.</param>
        /// <param name="inverted">If true, the filter elements NOT matching the filter criteria are chosen.</param>
        /// <returns name="ElementFilter">An Element Filter.  The filter should then be passed to a Collector node and the Collector retrieves elements that pass the filter.</returns>
        public static revitDB.ElementFilter FilterElementNumberParameter(
            int parameterId,
            double value,
            [DefaultArgument("0.0001")] double tolerance,
            revitDB.FilterNumericRuleEvaluator filterNumberRule,
            [DefaultArgument("false")] bool inverted)
        {
            revitDB.ParameterValueProvider provider = new revitDB.ParameterValueProvider(new revitDB.ElementId(parameterId));

            if (filterNumberRule != null)
            {
                revitDB.FilterRule filterRule = new revitDB.FilterDoubleRule(provider, filterNumberRule, value, tolerance);
                return(new revitDB.ElementParameterFilter(filterRule, inverted));
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            var parameterKey = default(Types.ParameterKey);

            if (!DA.GetData("ParameterKey", ref parameterKey))
            {
                return;
            }

            DA.DisableGapLogic();

            if (!TryGetParameterDefinition(parameterKey.Document, parameterKey.Id, out var storageType, out var parameterType))
            {
                if (parameterKey.Id.TryGetBuiltInParameter(out var builtInParameter))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Failed to found parameter '{DB.LabelUtils.GetLabelFor(builtInParameter)}' in Revit document.");
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Failed to found parameter '{parameterKey.Id.IntegerValue}' in Revit document.");
                }

                return;
            }

            var provider = new DB.ParameterValueProvider(parameterKey);

            DB.FilterRule rule = null;
            if (storageType == DB.StorageType.String)
            {
                DB.FilterStringRuleEvaluator ruleEvaluator = null;
                switch (Condition)
                {
                case ConditionType.NotEquals:
                case ConditionType.Equals:          ruleEvaluator = new DB.FilterStringEquals(); break;

                case ConditionType.Greater:         ruleEvaluator = new DB.FilterStringGreater(); break;

                case ConditionType.GreaterOrEqual:  ruleEvaluator = new DB.FilterStringGreaterOrEqual(); break;

                case ConditionType.Less:            ruleEvaluator = new DB.FilterStringLess(); break;

                case ConditionType.LessOrEqual:     ruleEvaluator = new DB.FilterStringLessOrEqual(); break;
                }

                var goo = default(GH_String);
                if (DA.GetData("Value", ref goo))
                {
                    rule = new DB.FilterStringRule(provider, ruleEvaluator, goo.Value, true);
                }
            }
            else
            {
                DB.FilterNumericRuleEvaluator ruleEvaluator = null;
                switch (Condition)
                {
                case ConditionType.NotEquals:
                case ConditionType.Equals:          ruleEvaluator = new DB.FilterNumericEquals(); break;

                case ConditionType.Greater:         ruleEvaluator = new DB.FilterNumericGreater(); break;

                case ConditionType.GreaterOrEqual:  ruleEvaluator = new DB.FilterNumericGreaterOrEqual(); break;

                case ConditionType.Less:            ruleEvaluator = new DB.FilterNumericLess(); break;

                case ConditionType.LessOrEqual:     ruleEvaluator = new DB.FilterNumericLessOrEqual(); break;
                }

                switch (storageType)
                {
                case DB.StorageType.Integer:
                {
                    var goo = default(GH_Integer);
                    if (DA.GetData("Value", ref goo))
                    {
                        rule = new DB.FilterIntegerRule(provider, ruleEvaluator, goo.Value);
                    }
                }
                break;

                case DB.StorageType.Double:
                {
                    var goo = default(GH_Number);
                    if (DA.GetData("Value", ref goo))
                    {
                        if (Condition == ConditionType.Equals || Condition == ConditionType.NotEquals)
                        {
                            if (parameterType == DB.ParameterType.Length || parameterType == DB.ParameterType.Area || parameterType == DB.ParameterType.Volume)
                            {
                                rule = new DB.FilterDoubleRule(provider, ruleEvaluator, ToHost(goo.Value, parameterType), ToHost(Revit.VertexTolerance, parameterType));
                            }
                            else
                            {
                                rule = new DB.FilterDoubleRule(provider, ruleEvaluator, ToHost(goo.Value, parameterType), 1e-6);
                            }
                        }
                        else
                        {
                            rule = new DB.FilterDoubleRule(provider, ruleEvaluator, ToHost(goo.Value, parameterType), 0.0);
                        }
                    }
                }
                break;

                case DB.StorageType.ElementId:
                {
                    switch (parameterType)
                    {
                    case (DB.ParameterType) int.MaxValue: // Category
                    {
                        var value = default(Types.Category);
                        if (DA.GetData("Value", ref value))
                        {
                            rule = new DB.FilterElementIdRule(provider, ruleEvaluator, value);
                        }
                    }
                    break;

                    case DB.ParameterType.Material:
                    {
                        var value = default(Types.Material);
                        if (DA.GetData("Value", ref value))
                        {
                            rule = new DB.FilterElementIdRule(provider, ruleEvaluator, value);
                        }
                    }
                    break;

                    case DB.ParameterType.FamilyType:
                    {
                        var value = default(Types.ElementType);
                        if (DA.GetData("Value", ref value))
                        {
                            rule = new DB.FilterElementIdRule(provider, ruleEvaluator, value);
                        }
                    }
                    break;

                    default:
                    {
                        var value = default(Types.Element);
                        if (DA.GetData("Value", ref value))
                        {
                            rule = new DB.FilterElementIdRule(provider, ruleEvaluator, value);
                        }
                    }
                    break;
                    }
                }
                break;
                }
            }

            if (rule is object)
            {
                if (Condition == ConditionType.NotEquals)
                {
                    DA.SetData("Rule", new DB.FilterInverseRule(rule));
                }
                else
                {
                    DA.SetData("Rule", rule);
                }
            }
        }