Exemple #1
0
        public static global::Revit.Elements.Element SetParameterValueByNameCaSeiNSeNSiTiVe(global::Revit.Elements.Element element,
                                                                                            string parameterName, object value)
        {
            //check Rhythm version
            //Rhythm.Utilities.VersionChecker();
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //create a list to hold the element ids and add them to it
            global::Revit.Elements.Parameter[] elementParams = element.Parameters;

            string paramToSet = null;
            //score of each match list
            List <int> values = new List <int>();

            //score the match in the parameter list
            foreach (var param in elementParams)
            {
                values.Add(StringComparisonUtilities.Compute(parameterName, param.Name));
            }
            //get the closest matching parameter name
            int minIndex = values.IndexOf(values.Min());

            paramToSet = elementParams[minIndex].Name;

            //Convert to a usable value
            var dynval = value as dynamic;

            TransactionManager.Instance.EnsureInTransaction(doc);
            //set that thing!
            var parameterValue = element.SetParameterByName(paramToSet, dynval);

            TransactionManager.Instance.TransactionTaskDone();

            return(element);
        }
Exemple #2
0
        public static object GetParameterValueByNameCaSeiNSeNSiTiVe(global::Revit.Elements.Element element,
                                                                    string parameterName)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //create a list to hold the element ids and add them to it
            Autodesk.Revit.DB.Element internalElement = element.InternalElement;

            global::Revit.Elements.Parameter[] elementParams = element.Parameters;

            string paramToSet = null;
            //score of each match list
            List <int> values = new List <int>();

            //score the match in the parameter list
            foreach (var param in elementParams)
            {
                values.Add(StringComparisonUtilities.Compute(parameterName, param.Name));
            }
            //get the closest matching parameter name
            int minIndex = values.IndexOf(values.Min());

            paramToSet = elementParams[minIndex].Name;
            //lookup and get the parameter value
            var result         = internalElement.LookupParameter(paramToSet);
            var parameterValue = global::Revit.Elements.InternalUtilities.ElementUtils.GetParameterValue(result);

            return(parameterValue);
        }
        private static List <NodeSearchElement> SearchAndDisplayResults(string searchString)
        {
            List <NodeSearchElement> results = new List <NodeSearchElement>();
            List <int> scores = new List <int>();

            foreach (NodeSearchElement nsm in MonocleViewExtension.dynView.Model.SearchModel.SearchEntries)
            {
                if (!nsm.IsVisibleInSearch)
                {
                    continue;
                }

                string searchableText = string.Empty;

                switch (searchCriteriaFlag)
                {
                case 1:
                    searchableText = nsm.Name;
                    break;

                case 2:
                    searchableText = nsm.Description;
                    break;

                case 3:
                    searchableText = nsm.Name + nsm.Description;
                    break;

                case 4:
                    searchableText = nsm.FullName;
                    break;

                case 5:
                    searchableText = nsm.Name + nsm.FullName;
                    break;

                case 6:
                    searchableText = nsm.FullName + nsm.Description;
                    break;

                case 7:
                    searchableText = nsm.Name + nsm.FullName + nsm.Description;
                    break;
                }


                if (searchableText.SimplifyString().Contains(searchString.SimplifyString()))
                {
                    results.Add(nsm);
                    nsm.Weight = StringComparisonUtilities.Compute(searchString.SimplifyString(), nsm.Name);
                }
            }

            return(results.OrderBy(r => r.Weight).ToList());
        }
 /// <summary>
 /// Do the search stuff n thangs
 /// </summary>
 private static List <NodeSearchElement> SearchAndDisplayResults(string searchString)
 {
     if (_excludeCustomNodes)
     {
         return(NodesToSearchOOTB.Where(n => SetSearchName(n).Contains(searchString))
                .OrderBy(n => StringComparisonUtilities.Compute(searchString, SetSearchName(n))).ToList());
     }
     //we reach this for all other searches
     return(NodesToSearch.Where(n => SetSearchName(n).Contains(searchString))
            .OrderBy(n => StringComparisonUtilities.Compute(searchString, SetSearchName(n))).ToList());
 }
        public static List <global::Revit.Elements.Element> ByParameterStringValue(List <global::Revit.Elements.Element> elements, string parameterName, string value, string filterMethod)
        {
            List <string> potentialFilterMethod = new List <string>(new string[] { "Contains", "DoesNotContain", "StartsWith", "DoesNotStartWith", "EndsWith", "DoesNotEndWith", "Equals", "DoesNotEqual", "==", "!=" });
            List <global::Revit.Elements.Element> filteredElements = null;
            string     filterMethodToUse = null;
            List <int> values            = new List <int>();

            foreach (string i in potentialFilterMethod)
            {
                values.Add(StringComparisonUtilities.Compute(filterMethod, i));
            }
            int minIndex = values.IndexOf(values.Min());

            filterMethodToUse = potentialFilterMethod[minIndex];
            //scenarios
            if (filterMethodToUse == "Contains")
            {
                filteredElements = new List <Element>(elements.Where(e => e.GetParameterValueByName(parameterName).ToString().Contains(value)).ToArray());
            }
            if (filterMethodToUse == "DoesNotContain")
            {
                filteredElements = new List <Element>(elements.Where(e => !e.GetParameterValueByName(parameterName).ToString().Contains(value)).ToArray());
            }
            if (filterMethodToUse == "StartsWith")
            {
                filteredElements = new List <Element>(elements.Where(e => e.GetParameterValueByName(parameterName).ToString().StartsWith(value)).ToArray());
            }
            if (filterMethodToUse == "DoesNotStartWith")
            {
                filteredElements = new List <Element>(elements.Where(e => !e.GetParameterValueByName(parameterName).ToString().StartsWith(value)).ToArray());
            }
            if (filterMethodToUse == "EndsWith")
            {
                filteredElements = new List <Element>(elements.Where(e => e.GetParameterValueByName(parameterName).ToString().EndsWith(value)).ToArray());
            }
            if (filterMethodToUse == "DoesNotEndWith")
            {
                filteredElements = new List <Element>(elements.Where(e => !e.GetParameterValueByName(parameterName).ToString().EndsWith(value)).ToArray());
            }
            if (filterMethodToUse == "Equals" || filterMethodToUse == "==")
            {
                filteredElements = new List <Element>(elements.Where(e => e.GetParameterValueByName(parameterName).ToString().Equals(value)).ToArray());
            }
            if (filterMethodToUse == "DoesNotEqual" || filterMethodToUse == "!=")
            {
                filteredElements = new List <Element>(elements.Where(e => !e.GetParameterValueByName(parameterName).ToString().Equals(value)).ToArray());
            }

            return(filteredElements);
        }
        public static List <global::Revit.Elements.Element> ByParameterNumericValue(List <global::Revit.Elements.Element> elements, string parameterName, double value, string filterMethod)
        {
            List <string> potentialFilterMethod = new List <string>(new string[] { "GreaterThan", "GreaterThanOrEqualTo", "LessThan", "LessThanOrEqualTo", ">", ">=", "<", "<=", "EqualTo", "==", "NotEqualTo", "!=" });
            List <global::Revit.Elements.Element> filteredElements = null;
            string     filterMethodToUse = null;
            List <int> values            = new List <int>();

            foreach (string i in potentialFilterMethod)
            {
                values.Add(StringComparisonUtilities.Compute(filterMethod, i));
            }
            int minIndex = values.IndexOf(values.Min());

            filterMethodToUse = potentialFilterMethod[minIndex];
            //scenarios
            if (filterMethodToUse == "GreaterThan" || filterMethodToUse == ">")
            {
                filteredElements = new List <Element>(elements.Where(e => Convert.ToDouble(e.GetParameterValueByName(parameterName)) > value).ToArray());
            }
            if (filterMethodToUse == "GreaterThanOrEqualTo" || filterMethodToUse == ">=")
            {
                filteredElements = new List <Element>(elements.Where(e => Convert.ToDouble(e.GetParameterValueByName(parameterName)) >= value).ToArray());
            }
            if (filterMethodToUse == "LessThan" || filterMethodToUse == "<")
            {
                filteredElements = new List <Element>(elements.Where(e => Convert.ToDouble(e.GetParameterValueByName(parameterName)) < value).ToArray());
            }
            if (filterMethodToUse == "LessThanOrEqualTo" || filterMethodToUse == "<=")
            {
                filteredElements = new List <Element>(elements.Where(e => Convert.ToDouble(e.GetParameterValueByName(parameterName)) <= value).ToArray());
            }
            if (filterMethodToUse == "EqualTo" || filterMethodToUse == "==")
            {
                filteredElements = new List <Element>(elements.Where(e => Convert.ToDouble(e.GetParameterValueByName(parameterName)) == value).ToArray());
            }
            if (filterMethodToUse == "NotEqualTo" || filterMethodToUse == "!=")
            {
                filteredElements = new List <Element>(elements.Where(e => Convert.ToDouble(e.GetParameterValueByName(parameterName)) != value).ToArray());
            }

            return(filteredElements);
        }
        public static List <global::Revit.Elements.Element> ByCategory(List <global::Revit.Elements.Element> elements, object category, string filterMethod)
        {
            List <string> potentialFilterMethod = new List <string>(new string[] { "Contains", "DoesNotContain", "StartsWith", "DoesNotStartWith", "EndsWith", "DoesNotEndWith", "Equals", "DoesNotEqual", "==", "!=" });
            List <global::Revit.Elements.Element> filteredElements = null;
            string     filterMethodToUse = null;
            List <int> values            = new List <int>();
            string     value             = null;

            foreach (string i in potentialFilterMethod)
            {
                values.Add(StringComparisonUtilities.Compute(filterMethod, i));
            }
            int minIndex = values.IndexOf(values.Min());

            filterMethodToUse = potentialFilterMethod[minIndex];
            //assign the value based on if the input is a string or category
            if (category is string)
            {
                value = category as string;
            }
            else
            {
                global::Revit.Elements.Category cat = (global::Revit.Elements.Category)category;
                value = cat.Name;
            }

            //scenarios
            if (filterMethodToUse == "Contains")
            {
                filteredElements = new List <Element>(elements.Where(e => e.GetCategory.Name.Contains(value)).ToArray());
            }
            if (filterMethodToUse == "DoesNotContain")
            {
                filteredElements = new List <Element>(elements.Where(e => !e.GetCategory.Name.Contains(value)).ToArray());
            }
            if (filterMethodToUse == "StartsWith")
            {
                filteredElements = new List <Element>(elements.Where(e => e.GetCategory.Name.StartsWith(value)).ToArray());
            }
            if (filterMethodToUse == "DoesNotStartWith")
            {
                filteredElements = new List <Element>(elements.Where(e => !e.GetCategory.Name.StartsWith(value)).ToArray());
            }
            if (filterMethodToUse == "EndsWith")
            {
                filteredElements = new List <Element>(elements.Where(e => e.GetCategory.Name.EndsWith(value)).ToArray());
            }
            if (filterMethodToUse == "DoesNotEndWith")
            {
                filteredElements = new List <Element>(elements.Where(e => !e.GetCategory.Name.EndsWith(value)).ToArray());
            }
            if (filterMethodToUse == "Equals" || filterMethodToUse == "==")
            {
                filteredElements = new List <Element>(elements.Where(e => e.GetCategory.Name.Equals(value)).ToArray());
            }
            if (filterMethodToUse == "DoesNotEqual" || filterMethodToUse == "!=")
            {
                filteredElements = new List <Element>(elements.Where(e => !e.GetCategory.Name.Equals(value)).ToArray());
            }

            return(filteredElements);
        }
Exemple #8
0
        /// <summary>
        /// Provides element filtering options by name. For the filter method, we are using something called "LevenshteinDistance".
        /// This was introduced to me by Eric Rudisaile + Kyle Martin here, http://dynamobim.org/fuzzy-string-matching/.
        /// </summary>
        /// <param name="elements">The elements to filter.</param>
        /// <param name="value">The value to filter by.</param>
        /// <param name="filterMethod">The method to filter by. This includes Contains, DoesNotContain, StartsWith, DoesNotStartWith, EndsWith, DoesNotEndWith, Equals, DoesNotEqual</param>
        /// <returns name="elements">The filtered elements.</returns>
        /// <search>
        /// ElementFilter,Filter.ByName
        /// </search>
        public static List <global::Revit.Elements.Element> ByName(List <global::Revit.Elements.Element> elements, string value, string filterMethod)
        {
            List <string> potentialFilterMethod = new List <string>(new string[] { "Contains", "DoesNotContain", "StartsWith", "DoesNotStartWith", "EndsWith", "DoesNotEndWith", "Equals", "DoesNotEqual", "==", "!=" });
            List <global::Revit.Elements.Element> filteredElements = null;
            string     filterMethodToUse = null;
            List <int> values            = new List <int>();

            foreach (string i in potentialFilterMethod)
            {
                values.Add(StringComparisonUtilities.Compute(filterMethod, i));
            }
            int minIndex = values.IndexOf(values.Min());

            filterMethodToUse = potentialFilterMethod[minIndex];
            //scenarios there is probably a better way to do this.
            switch (filterMethodToUse)
            {
            case "Contains":
                filteredElements = new List <Element>(elements.Where(e => e.Name.Contains(value)).ToArray());
                break;

            case "DoesNotContain":
                filteredElements = new List <Element>(elements.Where(e => !e.Name.Contains(value)).ToArray());
                break;

            case "StartsWith":
                filteredElements = new List <Element>(elements.Where(e => e.Name.StartsWith(value)).ToArray());
                break;

            case "DoesNotStartWith":
                filteredElements = new List <Element>(elements.Where(e => !e.Name.StartsWith(value)).ToArray());
                break;

            case "EndsWith":
                filteredElements = new List <Element>(elements.Where(e => e.Name.EndsWith(value)).ToArray());
                break;

            case "DoesNotEndWith":
                filteredElements = new List <Element>(elements.Where(e => !e.Name.EndsWith(value)).ToArray());
                break;

            case "Equals":
                filteredElements = new List <Element>(elements.Where(e => e.Name.Equals(value)).ToArray());
                break;

            case "==":
                filteredElements = new List <Element>(elements.Where(e => e.Name.Equals(value)).ToArray());
                break;

            case "DoesNotEqual":
                filteredElements = new List <Element>(elements.Where(e => !e.Name.Equals(value)).ToArray());
                break;

            case "!=":
                filteredElements = new List <Element>(elements.Where(e => !e.Name.Equals(value)).ToArray());
                break;

            default:
                filteredElements = elements;
                break;
            }

            return(filteredElements);
        }