Пример #1
0
        private IList <string> GetInternalValue(string valValue)
        {
            List <string> vResult     = new List <string>();
            Match         vRegexMatch = Regex.Match(valValue, @"([-+]?[0-9]*\.?[0-9]+)"); // Matches numbers including floats and integers.

            if (!vRegexMatch.Success)
            {
                return(vResult);
            }

            LibNumeric  vLibNum             = new LibNumeric();
            UnitsAbbrev vUnitsAbbreviations = new UnitsAbbrev();
            Dictionary <DisplayUnitType, string> vDictionary = vUnitsAbbreviations.UnitAbbrevations();
            IEnumerable <KeyValuePair <DisplayUnitType, string> > vMatches = vDictionary.Where(vItem => Regex.IsMatch(valValue, @"(^|\s)" + vItem.Value + "(\\s|$)")); //Finds the matching Display Unit Abbreviation.

            if (vLibNum.IsDouble(vRegexMatch.Value))
            {
                double vDoubleValue = double.Parse(vRegexMatch.Value, System.Globalization.CultureInfo.InvariantCulture);
                foreach (KeyValuePair <DisplayUnitType, string> vMatch in vMatches)
                {
                    DisplayUnitType vDisplayUnit       = vMatch.Key;
                    var             vInternalUnitValue = UnitUtils.ConvertToInternalUnits(vDoubleValue, vDisplayUnit);
                    vResult.Add(vInternalUnitValue.ToString());
                }
            }
            return(vResult);
        }
Пример #2
0
        public IList <Element> GetElementValueDouble(RevitParameter valRevitParameter, List <ElementId> valCategoryElementId, string valValue)
        {
            IList <Element> vResult = new List <Element>();

            foreach (var vCategoryId in valCategoryElementId)
            {
                BuiltInCategory        vBuiltInCategory = (BuiltInCategory)vCategoryId.IntegerValue;
                ParameterValueProvider vPovider         = new ParameterValueProvider(valRevitParameter.ElementId);
                string vRulestring = valValue;
                FilteredElementCollector vCollector = new FilteredElementCollector(_Doc);
                vCollector.OfCategory(vBuiltInCategory);
                LibNumeric insLibNumeric = new LibNumeric();
                double     ruleValDb     = 0.0;
                if (insLibNumeric.IsDouble(valValue))
                {
                    Double vNum = 0;
                    Double.TryParse(valValue, out vNum);
                    ruleValDb = vNum;
                }
                ParameterValueProvider pvp  = new ParameterValueProvider(valRevitParameter.ElementId);
                FilterNumericEquals    fnrv = new FilterNumericEquals();
                var vFilterDoubleRule       = new FilterDoubleRule(pvp, fnrv, ruleValDb, 10e-10);
                var epf = new ElementParameterFilter(vFilterDoubleRule);
                vCollector.WherePasses(epf);
                IList <Element> vElements = vCollector.ToElements();
                if (vElements != null)
                {
                    if (vElements.Count > 0)
                    {
                        vResult = vElements.Concat(vElements).ToList();
                    }
                }
            }
            return(vResult);
        }
Пример #3
0
        public IList <Element> GetBy(RevitParameter valRevitParameter, List <ElementId> valCategoryElementId, string valValue)
        {
            IList <Element> vResult        = new List <Element>();
            bool            vIsParse       = false;
            double          vData          = 0;
            string          vValueToString = valValue;


            if (!StringClasses.lstNames().Contains(valRevitParameter.Name))
            {
                if (IsParsed(valValue, out vData))
                {
                    valValue = vData.ToString();
                    vIsParse = true;
                }
            }



            LibNumeric insLibNumeric = new LibNumeric();

            if (insLibNumeric.IsDouble(valValue) && !StringClasses.lstNames().Contains(valRevitParameter.Name))
            {
                vResult = GetElementValueDouble(valRevitParameter, valCategoryElementId, valValue);
                if (vResult.Count == 0)
                {
                    if (vIsParse)
                    {
                        vResult = GetElementValueDoubleLessOrEqual(valRevitParameter, valCategoryElementId, valValue, vValueToString);

                        if (vResult.Count == 0)
                        {
                            vResult = GetElementValueDoubleGreaterOrEqual(valRevitParameter, valCategoryElementId, valValue, vValueToString);
                        }

                        if (vResult.Count == 0)
                        {
                            vResult = GetElementValueIntOrstring(valRevitParameter, valCategoryElementId, valValue);

                            if (vResult.Count <= 0)
                            {
                                vResult = FindByInternalValue(valRevitParameter, valCategoryElementId, valValue);
                            }
                        }
                    }
                }
            }
            else
            {
                vResult = GetElementValueIntOrstring(valRevitParameter, valCategoryElementId, valValue);

                if (vResult.Count <= 0)
                {
                    vResult = FindByInternalValue(valRevitParameter, valCategoryElementId, valValue);
                }
            }
            return(vResult);
        }
Пример #4
0
        private IList <Element> FindByInternalValue(RevitParameter valRevitParameter, List <ElementId> valCategoryElementId, string valValue)
        {
            LibNumeric     vLibNumeric     = new LibNumeric();
            List <Element> vResult         = new List <Element>();
            IList <string> vInternalValues = GetInternalValue(valValue);

            foreach (var vInternalValue in vInternalValues)
            {
                if (vLibNumeric.IsDouble(vInternalValue))
                {
                    IList <Element> vSearchResult = GetElementValueDouble(valRevitParameter, valCategoryElementId, vInternalValue);
                    vResult = vResult.Concat(vSearchResult).ToList();
                }
            }
            return(vResult);
        }
Пример #5
0
        private IList <Element> GetElementValueIntOrstring(RevitParameter valRevitParameter, List <ElementId> valCategoryElementId, string valValue)
        {
            IList <Element> vResult     = new List <Element>();
            IList <Element> vResultTemp = new List <Element>();

            foreach (var vCategoryId in valCategoryElementId)
            {
                IList <ElementFilter>  vList            = new List <ElementFilter>();
                BuiltInCategory        vBuiltInCategory = (BuiltInCategory)vCategoryId.IntegerValue;
                ParameterValueProvider vPovider         = new ParameterValueProvider(valRevitParameter.ElementId);
                string vRulestring = valValue;
                FilterStringRuleEvaluator vEvaluator = new FilterStringEquals();
                FilteredElementCollector  vCollector = new FilteredElementCollector(_Doc);
                vCollector.OfCategory(vBuiltInCategory);
                FilterRule             vRuleRulestring   = new FilterStringRule(vPovider, vEvaluator, vRulestring, false);
                ElementParameterFilter vFilterRulestring = new ElementParameterFilter(vRuleRulestring);
                LibNumeric             insLibNumeric     = new LibNumeric();
                if (insLibNumeric.IsInt(valValue))
                {
                    int vNum = 0;
                    int.TryParse(valValue, out vNum);
                    FilterNumericEquals vEvaluatorNumeri = new FilterNumericEquals();
                    int vRuleIntVal    = vNum;
                    var vFilterIntRule = new FilterIntegerRule(vPovider, vEvaluatorNumeri, vRuleIntVal);
                    var vElementParameterFilterIntRule = new ElementParameterFilter(vFilterIntRule);
                    vList.Add(vElementParameterFilterIntRule);
                }
                vList.Add(vFilterRulestring);
                LogicalOrFilter vLogicalOrFilter = new LogicalOrFilter(vList);
                vCollector.WherePasses(vLogicalOrFilter);
                IList <Element> vElements = vCollector.ToElements();
                if (vElements != null)
                {
                    if (vElements.Count > 0)
                    {
                        foreach (var vElement in vElements)
                        {
                            vResult.Add(vElement);
                        }
                    }
                }
            }
            return(vResult);
        }