Beispiel #1
0
        /// <summary>
        /// Translate to Revit Rule
        /// </summary>
        /// <param name="rule"></param>
        /// <param name="parameterId"></param>
        /// <returns></returns>
        public static Autodesk.Revit.DB.FilterRule ToRevitRule(this Grevit.Types.Rule rule, ElementId parameterId)
        {
            string methodname = "Create" + rule.equalityComparer + "Rule";


            if (
                rule.equalityComparer == "Equals" ||
                rule.equalityComparer == "NotEquals" ||
                rule.equalityComparer == "Greater" ||
                rule.equalityComparer == "Less" ||
                rule.equalityComparer == "GreaterOrEqual" ||
                rule.equalityComparer == "LessOrEqual"
                )
            {
                if (rule.value.GetType() == typeof(int))
                {
                    System.Reflection.MethodInfo methodInfo = typeof(ParameterFilterRuleFactory).GetMethod(methodname, new[] { typeof(ElementId), typeof(int) });
                    if (methodInfo != null)
                    {
                        return((FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (int)rule.value }));
                    }
                }
                else if (rule.value.GetType() == typeof(double))
                {
                    System.Reflection.MethodInfo methodInfo = typeof(ParameterFilterRuleFactory).GetMethod(methodname, new[] { typeof(ElementId), typeof(double), typeof(double) });
                    if (methodInfo != null)
                    {
                        return((FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (double)rule.value, 0 }));
                    }
                }
                else if (rule.value.GetType() == typeof(string))
                {
                    System.Reflection.MethodInfo methodInfo = typeof(ParameterFilterRuleFactory).GetMethod(methodname, new[] { typeof(ElementId), typeof(string), typeof(bool) });
                    if (methodInfo != null)
                    {
                        return((FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (string)rule.value, true }));
                    }
                }
            }
            else
            {
                if (rule.value.GetType() == typeof(string))
                {
                    System.Reflection.MethodInfo methodInfo = typeof(ParameterFilterRuleFactory).GetMethod(methodname, new[] { typeof(ElementId), typeof(string), typeof(bool) });
                    if (methodInfo != null)
                    {
                        return((FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (string)rule.value, true }));
                    }
                }
            }


            return(null);
        }
Beispiel #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_String name = new GH_String("");
            GH_String value = new GH_String("");
            GH_String eq = new GH_String("=");

            DA.GetData<GH_String>("Name", ref name);
            DA.GetData<GH_String>("Value", ref value);
            DA.GetData<GH_String>("Operator", ref eq);

            Grevit.Types.Rule rule = new Rule()
            {
                name = name.Value,
                value = value.Value,
                equalityComparer = eq.Value
            };

            DA.SetData("GrevitComponent", rule);
        }