Example #1
0
        public static List <MyParameter> GetParameterValues(Document doc, List <Element> elems, string ParamName, int startSymbols)
        {
            bool isTypeParam = false;

            if (ParamName == "Имя типа" || ParamName == "Имя типа")
            {
                isTypeParam = true;
            }

            HashSet <MyParameter> values = new HashSet <MyParameter>(); //список значений параметра

            foreach (Element elem in elems)
            {
                Parameter curParam = elem.LookupParameter(ParamName);

                if (curParam == null)
                {
                    ElementId typeElemId = elem.GetTypeId();
                    if (typeElemId == null)
                    {
                        continue;
                    }
                    if (typeElemId == ElementId.InvalidElementId)
                    {
                        continue;
                    }
                    Element typeElem = doc.GetElement(typeElemId);
                    curParam = typeElem.LookupParameter(ParamName);
                    if (curParam == null)
                    {
                        continue;
                    }
                }

                MyParameter mp = new MyParameter(curParam);
                if (!mp.HasValue && !isTypeParam)
                {
                    continue;
                }
                if (isTypeParam)
                {
                    Parameter typeParam = elem.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM);
                    if (!typeParam.HasValue)
                    {
                        continue;
                    }
                    string typeName = typeParam.AsValueString();
                    mp.Set(typeName);
                }

                if (startSymbols > 0)
                {
                    if (mp.RevitStorageType != StorageType.String)
                    {
                        throw new Exception("Критерий \"Начинается с\" доступен только для текстовых параметров");
                    }

                    string valTemp = mp.AsString();
                    string val     = "";
                    if (valTemp.Length < startSymbols)
                    {
                        val = valTemp;
                    }
                    else
                    {
                        val = valTemp.Substring(0, startSymbols);
                    }

                    mp.Set(val);
                }
                values.Add(mp);
            }


            List <MyParameter> listParams = values.ToList();

            listParams.Sort();
            return(listParams);
        }
Example #2
0
        public static FilterRule CreateRule(MyParameter mp, CriteriaType ctype)
        {
            Parameter  param = mp.RevitParameter;
            FilterRule rule  = null;

            if (ctype == CriteriaType.Equals)
            {
                switch (param.StorageType)
                {
                case StorageType.None:
                    break;

                case StorageType.Integer:
                    rule = ParameterFilterRuleFactory.CreateEqualsRule(param.Id, mp.AsInteger());
                    break;

                case StorageType.Double:
                    rule = ParameterFilterRuleFactory.CreateEqualsRule(param.Id, mp.AsDouble(), 0.0001);
                    break;

                case StorageType.String:
                    string val = mp.AsString();
                    if (val == null)
                    {
                        break;
                    }
                    rule = ParameterFilterRuleFactory.CreateEqualsRule(param.Id, val, true);
                    break;

                case StorageType.ElementId:
                    rule = ParameterFilterRuleFactory.CreateEqualsRule(param.Id, mp.AsElementId());
                    break;

                default:
                    break;
                }
            }

            if (ctype == CriteriaType.StartsWith)
            {
                switch (param.StorageType)
                {
                case StorageType.None:
                    break;

                case StorageType.String:
                    string val = mp.AsString();
                    if (val == null)
                    {
                        break;
                    }
                    rule = ParameterFilterRuleFactory.CreateBeginsWithRule(param.Id, val, true);
                    break;

                default:
                    break;
                }
            }

            if (rule == null)
            {
                throw new Exception("Не удалось создать правило фильтра");
            }
            return(rule);
        }