Esempio n. 1
0
 public static FilterByParameterText FilterByParameterText(string parameterName, TextComparisonType textComparisonType, string value)
 {
     return(new FilterByParameterText {
         ParameterName = parameterName, TextComparisonType = textComparisonType, Value = value
     });
 }
        public static ConstructionSetAbridged DefaultConstructionSetAbridged(string text, TextComparisonType textComparisonType, bool caseSensitive = true)
        {
            IEnumerable <ConstructionSetAbridged> constructionSetsAbridged = HoneybeeSchema.Helper.EnergyLibrary.DefaultConstructionSets;

            if (constructionSetsAbridged == null)
            {
                return(null);
            }

            foreach (ConstructionSetAbridged constructionSetAbridged in constructionSetsAbridged)
            {
                if (Core.Query.Compare(constructionSetAbridged.Identifier, text, textComparisonType, caseSensitive))
                {
                    return(constructionSetAbridged);
                }
            }

            return(null);
        }
        public static IEnumerable <ElementId> ElementIdsByParameter(this Document document, string parameterName, TextComparisonType textComparisonType, string value, IEnumerable <ElementId> ids = null)
        {
            if (document == null)
            {
                return(null);
            }

            HashSet <ElementId> result = new HashSet <ElementId>();

            if (ids != null && ids.Count() == 0)
            {
                return(result);
            }

            FilteredElementCollector collector = ids == null ? new FilteredElementCollector(document) : new FilteredElementCollector(document, ids.ToList());

            foreach (Element element in collector.WherePasses(new LogicalOrFilter(new ElementIsElementTypeFilter(), new ElementIsElementTypeFilter(true))))
            {
                Parameter param = element.LookupParameter(parameterName);
                if (param != null && param.HasValue)
                {
                    string paramValue;
                    if (param.StorageType == StorageType.String)
                    {
                        paramValue = param.AsString();
                    }
                    else if (param.StorageType == StorageType.ElementId || (param.StorageType == StorageType.Integer && param.Definition.ParameterType != ParameterType.YesNo))
                    {
                        paramValue = param.AsValueString();
                    }
                    else
                    {
                        continue;
                    }

                    bool pass = false;
                    switch (textComparisonType)
                    {
                    case TextComparisonType.Contains:
                        pass = paramValue.Contains(value);
                        break;

                    case TextComparisonType.ContainsNot:
                        pass = !paramValue.Contains(value);
                        break;

                    case TextComparisonType.EndsWith:
                        pass = paramValue.EndsWith(value);
                        break;

                    case TextComparisonType.Equal:
                        pass = paramValue == value;
                        break;

                    case TextComparisonType.NotEqual:
                        pass = paramValue != value;
                        break;

                    case TextComparisonType.StartsWith:
                        pass = paramValue.StartsWith(value);
                        break;
                    }

                    if (pass)
                    {
                        result.Add(element.Id);
                    }
                }
            }

            return(result);
        }