Пример #1
0
        /// <summary>
        /// Returns all elements at a given workset.
        /// </summary>
        /// <param name="workset">Workset that we are filtering for.</param>
        /// <returns name="Element">Elements that passed the workset filter.</returns>
        public static IList <Element> ByWorkset(Workset workset)
        {
            var doc      = DocumentManager.Instance.CurrentDBDocument;
            var filter   = new Autodesk.Revit.DB.ElementWorksetFilter(workset.InternalWorkset.Id, false);
            var elements = new Autodesk.Revit.DB.FilteredElementCollector(doc)
                           .WherePasses(filter)
                           .ToElements()
                           .Select(x => x.ToDSType(true))
                           .ToList();

            return(elements.Any() ? elements : Enumerable.Empty <Element>().ToList());
        }
Пример #2
0
        public static bool Exists(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            var doc = DocumentManager.Instance.CurrentDBDocument;
            var fp  = new Autodesk.Revit.DB.FilteredElementCollector(doc)
                      .OfClass(typeof(Autodesk.Revit.DB.FillPatternElement))
                      .WhereElementIsNotElementType()
                      .Where(x => x.Name == name)
                      .ToList();

            return(fp.Any());
        }
Пример #3
0
        /// <summary>
        ///     Select all elements by design option and category.
        /// </summary>
        /// <param name="category">Category to filter for.</param>
        /// <param name="designOption">Design Option to filter for.</param>
        /// <returns name="Element">Elements.</returns>
        public static IList <Element> ByCategoryAndDesignOption(Category category, Element designOption)
        {
            var doc = DocumentManager.Instance.CurrentDBDocument;
            var bic = (Autodesk.Revit.DB.BuiltInCategory)Enum.ToObject(typeof(Autodesk.Revit.DB.BuiltInCategory), category.Id);

            // create design option filter
            var filter = new Autodesk.Revit.DB.ElementDesignOptionFilter(new Autodesk.Revit.DB.ElementId(designOption.Id));

            // select elements
            var elements = new Autodesk.Revit.DB.FilteredElementCollector(doc)
                           .OfCategory(bic)
                           .WherePasses(filter)
                           .WhereElementIsNotElementType()
                           .ToElements()
                           .Select(x => x.ToDSType(true))
                           .ToList();

            return(elements.Any() ? elements : Enumerable.Empty <Element>().ToList());
        }
Пример #4
0
        public static Dictionary <string, List <object> > GetDocuments()
        {
            var result = new Dictionary <string, List <object> >()
            {
                { "Link Doc", new List <object>() },
                { "Link Name", new List <object>() },
                { "Link Instance", new List <object>() },
                { "Link Path", new List <object>() }
            };

            var doc       = DocumentManager.Instance.CurrentDBDocument;
            var instances = new Autodesk.Revit.DB.FilteredElementCollector(doc)
                            .OfClass(typeof(Autodesk.Revit.DB.RevitLinkInstance))
                            .Cast <Autodesk.Revit.DB.RevitLinkInstance>()
                            .ToList();

            if (!instances.Any())
            {
                return(result);
            }

            var linkDocs      = new List <object>();
            var linkNames     = new List <object>();
            var linkPaths     = new List <object>();
            var linkInstances = new List <object>();

            foreach (var inst in instances)
            {
                linkInstances.Add(inst.ToDSType(true));
                linkDocs.Add(inst.GetLinkDocument());
                linkNames.Add(inst.Name);
                linkPaths.Add(inst.GetLinkDocument()?.PathName);
            }

            result["Link Doc"]      = linkDocs;
            result["Link Name"]     = linkNames;
            result["Link Instance"] = linkInstances;
            result["Link Path"]     = linkPaths;

            return(result);
        }
Пример #5
0
        /// <summary>
        /// Checks whether an Element is visible in given View.
        /// </summary>
        /// <param name="element">Element to check.</param>
        /// <param name="view">View to check visibility in.</param>
        /// <returns>True if Element is visible in View, otherwise false.</returns>
        public static bool IsVisible(Element element, View view)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }
            if (view == null || !(view.InternalElement is Autodesk.Revit.DB.View v))
            {
                throw new ArgumentNullException(nameof(view));
            }

            var doc = DocumentManager.Instance.CurrentDBDocument;
            var e   = element.InternalElement;

            var found = new Autodesk.Revit.DB.FilteredElementCollector(doc, v.Id)
                        .OfCategoryId(e.Category.Id)
                        .WhereElementIsNotElementType()
                        .Where(x => x.Id == e.Id);

            return(found.Any());
        }
Пример #6
0
        public static Element GetByName(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            var doc = DocumentManager.Instance.CurrentDBDocument;
            var fp  = new Autodesk.Revit.DB.FilteredElementCollector(doc)
                      .OfClass(typeof(Autodesk.Revit.DB.FillPatternElement))
                      .WhereElementIsNotElementType()
                      .Where(x => x.Name == name)
                      .ToList();

            if (fp.Any())
            {
                return(fp.First().ToDSType(true));
            }

            throw new Exception("Could not find Fill Pattern with given name.");
        }
Пример #7
0
        /// <summary>
        /// Parameter value filter.
        /// </summary>
        /// <param name="elementType"></param>
        /// <param name="parameterName"></param>
        /// <param name="evaluator"></param>
        /// <param name="value"></param>
        /// <param name="rule"></param>
        /// <returns name="Element">Element.</returns>
        public static List <Element> ByParameterValue(
            Type elementType,
            string parameterName,
            object evaluator,
            object value,
            [DefaultArgument("Selection.Select.GetNull()")] string rule)
        {
            var doc         = DocumentManager.Instance.CurrentDBDocument;
            var numericRule = FilterNumericValueRule.DoubleRule;

            if (rule != null)
            {
                numericRule = (FilterNumericValueRule)Enum.Parse(typeof(FilterNumericValueRule), rule);
            }

            var e = new Autodesk.Revit.DB.FilteredElementCollector(doc)
                    .OfClass(elementType)
                    .WhereElementIsNotElementType()
                    .First();

            // get parameter value provider
            Autodesk.Revit.DB.ParameterValueProvider pvp;
            try
            {
                if (Enum.TryParse(parameterName, out Autodesk.Revit.DB.BuiltInParameter bip))
                {
                    // process as bip
                    pvp = new Autodesk.Revit.DB.ParameterValueProvider(new Autodesk.Revit.DB.ElementId((int)bip));
                }
                else
                {
                    // process as regular param
                    var p = e.LookupParameter(parameterName);
                    pvp = new Autodesk.Revit.DB.ParameterValueProvider(p.Id);
                }
            }
            catch (Exception)
            {
                throw new ArgumentException("parameterName");
            }


            // get filter rule
            Autodesk.Revit.DB.FilterRule filterRule;
            switch (Type.GetTypeCode(value.GetType()))
            {
            case TypeCode.String:
                var fsre = (Autodesk.Revit.DB.FilterStringRuleEvaluator)evaluator;
                filterRule = new Autodesk.Revit.DB.FilterStringRule(pvp, fsre, (string)value, true);
                break;

            default:
                var fnre = (Autodesk.Revit.DB.FilterNumericRuleEvaluator)evaluator;
                switch (numericRule)
                {
                case FilterNumericValueRule.DoubleRule:
                    filterRule = new Autodesk.Revit.DB.FilterDoubleRule(pvp, fnre, (double)value, 0.001);
                    break;

                case FilterNumericValueRule.ElementIdRule:
                    var id = ((Element)value).InternalElement.Id;
                    filterRule = new Autodesk.Revit.DB.FilterElementIdRule(pvp, fnre, id);
                    break;

                case FilterNumericValueRule.IntegerRule:
                    filterRule = new Autodesk.Revit.DB.FilterIntegerRule(pvp, fnre, (int)value);
                    break;

                default:
                    throw new ArgumentException("rule");
                }
                break;
            }

            // create parameter filter
            var epf = new Autodesk.Revit.DB.ElementParameterFilter(filterRule);

            // return collection
            var output = new Autodesk.Revit.DB.FilteredElementCollector(doc).OfClass(elementType).WherePasses(epf).ToElements();

            return(output.Any() ? output.Select(x => x.ToDSType(true)).ToList() : Enumerable.Empty <Element>().ToList());
        }