public static Dictionary <string, object> ByCategory(Revit.Elements.Category category)
        {
            var                      categoryId = category.Id;
            Document                 doc        = DocumentManager.Instance.CurrentDBDocument;
            BuiltInCategory          myCatEnum  = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), categoryId.ToString());
            FilteredElementCollector elements   = new FilteredElementCollector(doc).OfCategory(myCatEnum).WhereElementIsNotElementType();
            //grabs the elements from the collection
            var elementCollection = elements.ToElements();
            //generates a list to convert to a usable type in Dynamo
            List <Revit.Elements.Element> revitElements = new List <Revit.Elements.Element>();

            foreach (var element in elementCollection)
            {
                revitElements.Add(element.ToDSType(true));
            }
            ;
            List <string> stringList = new List <string>();

            foreach (Autodesk.Revit.DB.Element element in elementCollection)
            {
                stringList.Add(element.Name);
            }
            ;
            //returns the outputs
            var outInfo = new Dictionary <string, object>
            {
                { "elements", revitElements },
                { "names", stringList },
                { "count", elements.GetElementCount() }
            };

            return(outInfo);
        }
Example #2
0
        public static List <Revit.Elements.Element> GetElementFromLinkDocument(Revit.Elements.Category Category, Autodesk.Revit.DB.Document Document)
        {
            var cate    = (BuiltInCategory)Enum.ToObject(typeof(BuiltInCategory), Category.Id);
            var filter  = new ElementCategoryFilter(cate);
            var Element = new FilteredElementCollector(Document).WherePasses(filter).WhereElementIsNotElementType().ToElements().Select(x => x.ToDSType(true)).ToList();

            return(Element);
        }
Example #3
0
        private static ScheduleView CreateTestView()
        {
            var view = ScheduleView.CreateSchedule(Category.ByName("OST_GenericModel"), "KeySchedule_Test", ScheduleView.ScheduleType.KeySchedule.ToString());

            Assert.NotNull(view);

            return(view);
        }
        public static Dictionary <string, object> ElementTaggedStatus(Revit.Elements.Views.View view,
                                                                      Revit.Elements.Category category)
        {
            var             viewId     = view.InternalElement.Id;
            var             categoryId = category.Id;
            Document        doc        = DocumentManager.Instance.CurrentDBDocument;
            BuiltInCategory myCatEnum  = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), categoryId.ToString());

            List <Revit.Elements.Element> notTaggedList = new List <Revit.Elements.Element>();

            foreach (Autodesk.Revit.DB.Element e in new FilteredElementCollector(doc, viewId)
                     .OfCategory(myCatEnum).WhereElementIsNotElementType())
            {
                if (new FilteredElementCollector(doc, viewId)
                    .OfClass(typeof(IndependentTag))
                    .Cast <IndependentTag>()
                    .FirstOrDefault(q => q.TaggedLocalElementId == e.Id) == null)
                {
                    notTaggedList.Add(e.ToDSType(true));
                }
            }

            List <Revit.Elements.Element> allTagged = new List <Revit.Elements.Element>();
            FilteredElementCollector      allInView =
                new FilteredElementCollector(doc, viewId)
                .OfClass(typeof(IndependentTag)).WhereElementIsNotElementType();
            var elementCollection = allInView.ToElements();

            foreach (Autodesk.Revit.DB.Element t in elementCollection)
            {
                var tag = (Tag)t.ToDSType(true);
                allTagged.Add(tag.TaggedElement);
            }
            List <Revit.Elements.Element> taggedList = new List <Revit.Elements.Element>();

            foreach (Element element in allTagged)
            {
                if (element.InternalElement.Category.Id.ToString() == category.Id.ToString())
                {
                    taggedList.Add(element.InternalElement.ToDSType(true));
                }
            }

            //returns the outputs
            var outInfo = new Dictionary <string, object>
            {
                { "notTagged", notTaggedList },
                { "tagged", taggedList }
            };

            return(outInfo);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public static IList <Element> ByCategory(Category category)
        {
            var doc    = DocumentManager.Instance.CurrentDBDocument;
            var filter = new Autodesk.Revit.DB.ElementMulticategoryFilter(new List <Autodesk.Revit.DB.ElementId>
            {
                new Autodesk.Revit.DB.ElementId(category.Id)
            });

            return(new Autodesk.Revit.DB.FilteredElementCollector(doc)
                   .WhereElementIsNotElementType()
                   .WherePasses(filter)
                   .Select(x => x.ToDSType(true))
                   .ToList());
        }
Example #6
0
        /// <summary>
        /// Select Elements by Category and View.
        /// </summary>
        /// <param name="category">Category to filter for.</param>
        /// <param name="view">View to filter for.</param>
        /// <returns name="Element">Element.</returns>
        public static List <Element> ByCategoryAndView(Category category, View view)
        {
            var v   = (Autodesk.Revit.DB.View)view.InternalElement;
            var bic = (Autodesk.Revit.DB.BuiltInCategory)Enum.ToObject(typeof(Autodesk.Revit.DB.BuiltInCategory), category.Id);
            var doc = DocumentManager.Instance.CurrentDBDocument;

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

            return(elements.Any() ? elements : Enumerable.Empty <Element>().ToList());
        }
Example #7
0
        /// <summary>
        /// Selects all Family Symbol types in a category, but excludes instances of those elements.  The node does not work with System familes because System Families do not have a Family Sybmol.
        /// </summary>
        /// <param name="category">The categoryId of the elements you wish to select.</param>
        /// <param name="inverted">If false, elements in the chosen category will be selected.  If true, elements NOT in the chosen category will be selected.</param>
        /// <param name="document">A Autodesk.Revit.DB.Document object.  This does not work with Dynamo document objects.</param>
        /// <returns name="Elements">A list of Dynamo elements that pass the filer.</returns>
        public static IList <DynElem> AllFamilyTypesOfCategory(DynCat category,
                                                               [DefaultArgument("false")] bool inverted,
                                                               [DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc document)
        {
            SynthCollect collector = new SynthCollect(document);

            // Select only elements that are Family Symbols
            List <RevitDB.ElementFilter> filters = new List <Autodesk.Revit.DB.ElementFilter>();

            filters.Add(SynthCollectFilter.FilterElementClass(typeof(RevitDB.FamilySymbol), false));
            filters.Add(SynthCollectFilter.FilterElementCategory(category, inverted));

            SynthCollect.SetFilters(collector, filters);

            return(SynthCollect.ToElements(collector));
        }
Example #8
0
        /// <summary>
        /// Selects all instance elements in a category, excludes element types.
        /// </summary>
        /// <param name="category">The categoryId of the elements you wish to select.</param>
        /// <param name="inverted">If false, elements in the chosen category will be selected.  If true, elements NOT in the chosen category will be selected.</param>
        /// <param name="document">A Autodesk.Revit.DB.Document object.  This does not work with Dynamo document objects.</param>
        /// <returns name="Elements">A list of Dynamo elements that pass the filer.</returns>
        public static IList <DynElem> AllElementsOfCategory(DynCat category,
                                                            [DefaultArgument("false")] bool inverted,
                                                            [DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc document)
        {
            SynthCollect collector = new SynthCollect(document);

            // Select only elements that are NOT Types (the filter is inverted)
            List <RevitDB.ElementFilter> filters = new List <Autodesk.Revit.DB.ElementFilter>();

            filters.Add(SynthCollectFilter.FilterElementIsElementType(true));
            filters.Add(SynthCollectFilter.FilterElementCategory(category, inverted));

            SynthCollect.SetFilters(collector, filters);

            return(SynthCollect.ToElements(collector));
        }
        /// <summary>
        /// Get all objects of a certain category from a linked interface
        /// </summary>
        /// <param name="LinkInstance">Link Instance</param>
        /// <param name="Category">Category</param>
        /// <returns></returns>
        public static Autodesk.Revit.DB.Category GetRevitCategory(Revit.Elements.Category Category)
        {
            System.Reflection.PropertyInfo IntProp = Category.GetType().GetProperty("InternalCategory", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            if (IntProp == null)
            {
                throw new ArgumentException("No category matching");
            }

            Autodesk.Revit.DB.Category Cat1 = IntProp.GetValue(Category) as Autodesk.Revit.DB.Category;

            if (Cat1 == null)
            {
                throw new ArgumentException("Could not find category");
            }

            return(Cat1);
        }
Example #10
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());
        }
Example #11
0
        public static Dictionary <string, object> IntersectionByElementCategory(Revit.Elements.Category category, bool refresh = false)
        {
            List <Revit.Elements.Element>         elList = new List <Revit.Elements.Element>();
            List <List <Revit.Elements.Element> > inList = new List <List <Revit.Elements.Element> >();

            if (refresh)
            {
                BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString());
                Document        doc       = DocumentManager.Instance.CurrentDBDocument;
                //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                ElementCategoryFilter    filter    = new ElementCategoryFilter(myCatEnum);
                FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType();

                foreach (Autodesk.Revit.DB.Element e in collector)
                {
                    List <Revit.Elements.Element> intersList = new List <Revit.Elements.Element>();
                    DynaFunctions f = new DynaFunctions();
                    ElementIntersectsElementFilter interFiler = new ElementIntersectsElementFilter(e);
                    FilteredElementCollector       interElem  = new FilteredElementCollector(doc).WherePasses(interFiler).WhereElementIsNotElementType();
                    if (interElem.GetElementCount() > 0)
                    {
                        elList.Add(doc.GetElement(e.Id).ToDSType(true));
                        foreach (Autodesk.Revit.DB.Element el in interElem)
                        {
                            intersList.Add(doc.GetElement(el.Id).ToDSType(true));
                        }
                        inList.Add(intersList);
                    }
                }
            }
            return(new Dictionary <string, object>
            {
                { "Elements", elList },
                { "Intersections", inList },
            });
        }
Example #12
0
        public void AddScheduleFilter_ValidArgs()
        {
            var view = ScheduleView.CreateSchedule(Category.ByName("OST_Walls"), "WallSchedule_Test", ScheduleView.ScheduleType.RegularSchedule.ToString());

            Assert.NotNull(view);

            // get a list of schedulable fields and add "Width" field to schedule
            var schedulableFields = view.SchedulableFields;

            Assert.Greater(schedulableFields.Count, 0);

            var fieldToAdd = schedulableFields
                             .FirstOrDefault(x => x.Name == "Width");

            Assert.NotNull(fieldToAdd);

            view.AddFields(new List <Revit.Schedules.SchedulableField> {
                fieldToAdd
            });
            Assert.Greater(view.Fields.Count, 0);

            // create new schedule filter and add it to schedule
            var field = view.Fields
                        .FirstOrDefault(x => x.Name == "Width");

            Assert.NotNull(field);

            var filter = Revit.Schedules.ScheduleFilter.ByFieldTypeAndValue(field, Autodesk.Revit.DB.ScheduleFilterType.Equal.ToString(), 0.1);

            Assert.NotNull(filter);

            view.AddFilters(new List <Revit.Schedules.ScheduleFilter> {
                filter
            });
            Assert.Greater(view.ScheduleFilters.Count, 0);
        }
        public static List <Revit.Elements.Element> FindAllOfCategoryInFile(string SourceFilename, Revit.Elements.Category DynCat)
        {
            Autodesk.Revit.DB.Document      doc   = DocumentManager.Instance.CurrentDBDocument;
            Autodesk.Revit.UI.UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
            //TransactionManager.Instance.EnsureInTransaction(doc);

            Document WallDoc = uiapp.Application.OpenDocumentFile(SourceFilename);

            Autodesk.Revit.DB.Category FoundCat = GetRevitCategory(DynCat);

            BuiltInCategory BIcat = (BuiltInCategory)DynCat.Id;

            var Elements = new FilteredElementCollector(WallDoc)
                           .OfCategory(BIcat);

            List <Revit.Elements.Element> AllElements = new List <Revit.Elements.Element>();

            foreach (Autodesk.Revit.DB.Element TempEle in Elements)
            {
                Revit.Elements.Element WrappedEle = TempEle.ToDSType(false);
                AllElements.Add(WrappedEle);
            }

            return(AllElements);
        }
Example #14
0
 public void ByCategoryNameType_NullArgs()
 {
     Assert.Throws(typeof(ArgumentNullException), () => ScheduleView.CreateSchedule(null, "KeySchedule_Test", ScheduleView.ScheduleType.KeySchedule.ToString()));
     Assert.Throws(typeof(ArgumentNullException), () => ScheduleView.CreateSchedule(Category.ByName("OST_GenericModel"), null, ScheduleView.ScheduleType.KeySchedule.ToString()));
     Assert.Throws(typeof(ArgumentNullException), () => ScheduleView.CreateSchedule(Category.ByName("OST_GenericModel"), "KeySchedule_Test", null));
 }
Example #15
0
        public static Dictionary <string, object> ActiveSelectionOfCategory(Boolean refresh = false, Revit.Elements.Category category = null)
        {
            string message = "Select something";
            List <Revit.Elements.Element> elements = new List <Revit.Elements.Element>();

            if (refresh)
            {
                try
                {
                    Document      doc   = DocumentManager.Instance.CurrentDBDocument;
                    UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                    Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                    UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                    // Get the element selection of current document.
                    Selection selection = uidoc.Selection;
                    ICollection <ElementId> selectedIds = uidoc.Selection.GetElementIds();
                    BuiltInCategory         myCatEnum   = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString());

                    if (0 == selectedIds.Count)
                    {
                        // If no elements selected.
                        message = "You haven't selected any elements.";
                    }
                    else
                    {
                        foreach (ElementId id in selectedIds)
                        {
                            if (doc.GetElement(id).Category.Name == category.Name)
                            {
                                elements.Add(doc.GetElement(id).ToDSType(true));
                            }
                        }
                        if (elements.Count > 0)
                        {
                            message = "Executed";
                        }
                        else
                        {
                            message = "No elements of selected category";
                        }
                    }
                }
                catch (Exception e)
                {
                    message = e.Message;
                }
            }
            return(new Dictionary <string, object>
            {
                { "elements", elements },
                { "message", message },
            });
        }
Example #16
0
        /// <summary>
        /// Counts the number of datums in each drawing
        /// </summary>
        /// <param name="sheets">sheets to check</param>
        /// <param name="category">category of elements to count</param>
        /// <returns name="results">count of datums in each sheet</returns>
        /// <search>
        /// mace, structural, general, arrangement, drawing, datum, count, number
        /// </search>
        public static string NumberOfElementsInEachDrawing(Revit.Elements.Views.Sheet sheets, Revit.Elements.Category category)
        {
            Document doc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;

            List <List <Revit.Elements.Element> > elements = Collector.ElementsInSheetByCategory(sheets, category);

            List <int> counts = new List <int>();

            foreach (List <Revit.Elements.Element> e in elements)
            {
                counts.Add(e.Count);
            }

            string output = sheets.SheetNumber.ToString() + " - " + sheets.SheetName.ToString() + " = " + counts[0].ToString();

            return(output);
        }
Example #17
0
        public static Dictionary <string, object> SelectFromViewportOfCategoryRetainOrder(Boolean refresh = false, Revit.Elements.Category category = null)
        {
            string message = "Select something";
            List <Revit.Elements.Element> elements = new List <Revit.Elements.Element>();

            if (refresh)
            {
                try
                {
                    Document      doc   = DocumentManager.Instance.CurrentDBDocument;
                    UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                    Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                    UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                    // Get the element selection of current document.
                    Selection selection = uidoc.Selection;

                    List <Reference> selectedElements = new List <Reference>();
                    ISelectionFilter categoryFitler   = new CategorySelectionFilter(category.Name);

                    bool flag = true;
                    while (flag)
                    {
                        try
                        {
                            Reference reference = uidoc.Selection.PickObject(ObjectType.Element, categoryFitler, "Pick elements in the desired order and hit ESC to stop picking.");
                            selectedElements.Add(reference);
                        }
                        catch
                        {
                            flag = false;
                        }
                    }

                    if (0 == selectedElements.Count)
                    {
                        // If no elements selected.
                        message = "You haven't selected any elements.";
                    }
                    else
                    {
                        foreach (Reference e in selectedElements)
                        {
                            elements.Add(doc.GetElement(e).ToDSType(true));
                        }
                        message = "Executed";
                    }
                }
                catch (Exception e)
                {
                    message = e.Message;
                }
            }
            return(new Dictionary <string, object>
            {
                { "elements", elements },
                { "message", message },
            });
        }
Example #18
0
        public static DynamoRevitElements.DirectShape CreateRevitMass(DynamoElements.Solid BuildingSolid, DynamoRevitElements.Category Category)
        {
            if (BuildingSolid == null)
            {
                throw new ArgumentNullException(nameof(BuildingSolid));
            }

            var revitCategory = Document.Settings.Categories.get_Item(Category.Name);

            TransactionManager.Instance.EnsureInTransaction(Document);

            var revitBuilding = RevitElements.DirectShape.CreateElement(Document, revitCategory.Id);

            try
            {
                revitBuilding.SetShape(new[] { DynamoToRevitBRep.ToRevitType(BuildingSolid) });
            }
            catch (Exception ex)
            {
                try
                {
                    revitBuilding.SetShape(BuildingSolid.ToRevitType());
                }
                catch
                {
                    throw new ArgumentException(ex.Message);
                }
            }

            TransactionManager.Instance.TransactionTaskDone();

            revitCategory.Dispose();

            var directShape = revitBuilding.ToDSType(false) as DynamoRevitElements.DirectShape;

            revitBuilding.Dispose();

            return(directShape);
        }
Example #19
0
        public static Dictionary <string, object> ElementParametersByCategoryFromDocument(Autodesk.Revit.DB.Document doc, Revit.Elements.Category category, List <string> parameters = null, Boolean refresh = false)
        {
            string executed = "";
            List <Revit.Elements.Element> elList = new List <Revit.Elements.Element>();
            List <List <object> >         values = new List <List <object> >();

            if (refresh)
            {
                BuiltInCategory       myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString());
                ElementCategoryFilter filter    = new ElementCategoryFilter(myCatEnum);

                //Document doc = DocumentManager.Instance.CurrentDBDocument;
                //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                FilteredElementCollector  collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType();
                List <Definition>         param     = new List <Definition>();
                Autodesk.Revit.DB.Element e         = collector.FirstElement();
                ParameterSet paramSet = e.Parameters;

                foreach (string s in parameters)
                {
                    foreach (Autodesk.Revit.DB.Parameter p in paramSet)
                    {
                        if (p.Definition.Name == s)
                        {
                            param.Add(p.Definition);
                        }
                    }
                }

                if (param.Count != parameters.Count)
                {
                    executed = "Check parameters name";
                }
                else
                {
                    executed = "Executed";

                    foreach (Autodesk.Revit.DB.Element el in collector)
                    {
                        List <object> elParams = new List <object>();
                        DynaFunctions f        = new DynaFunctions();
                        elList.Add(doc.GetElement(el.Id).ToDSType(true));
                        foreach (Definition p in param)
                        {
                            switch (el.get_Parameter(p).StorageType)
                            {
                            case StorageType.Double: elParams.Add(el.get_Parameter(p).AsDouble()); break;

                            case StorageType.Integer: elParams.Add(el.get_Parameter(p).AsInteger()); break;

                            case StorageType.String: elParams.Add(el.get_Parameter(p).AsString()); break;

                            case StorageType.ElementId: elParams.Add(el.get_Parameter(p).AsValueString()); break;
                            }
                        }
                        values.Add(elParams);
                    }
                }
            }

            return(new Dictionary <string, object>
            {
                { "Elements", elList },
                { "Values", values },
                { "Result", executed }
            });
        }
Example #20
0
        public static Dictionary <string, object> ElementByCategoryFromDocument(Autodesk.Revit.DB.Document doc, Revit.Elements.Category category, Boolean refresh = false)
        {
            List <Revit.Elements.Element> elList = new List <Revit.Elements.Element>();

            if (refresh)
            {
                BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString());

                ElementCategoryFilter filter = new ElementCategoryFilter(myCatEnum);

                //Document doc = DocumentManager.Instance.CurrentDBDocument;
                //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType();
                foreach (Autodesk.Revit.DB.Element e in collector)
                {
                    DynaFunctions f = new DynaFunctions();
                    elList.Add(doc.GetElement(e.Id).ToDSType(true));
                }
            }

            return(new Dictionary <string, object>
            {
                { "Elements", elList },
            });
        }
 /// <summary>
 /// Creates a ElementFilter that passes elements in the category.  The filter should then be passed to a Collector node and the Collector retrieves elements that pass the filter.
 /// </summary>
 /// <param name="category">A dynamo wrapped catogry.</param>
 /// <param name="inverted">If true, the filter elements NOT matching the filter criteria are chosen.</param>
 /// <returns name="ElementFilter">An Element Filter.  The filter should then be passed to a Collector node and the Collector retrieves elements that pass the filter.</returns>
 public static revitDB.ElementFilter FilterElementCategory(DynCat category, [DefaultArgument("false")] bool inverted)
 {
     return(new revitDB.ElementCategoryFilter(new revitDB.ElementId(category.Id), inverted));
 }
Example #22
0
 private static List <int> GetIntersectingElementIds(Element intersectionElement, Revit.Elements.Category category)
 {
     return(intersectionElement.GetIntersectingElementsOfCategory(category)
            .Select(elem => elem.Id)
            .ToList());
 }
Example #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="category"></param>
        /// <param name="refresh"></param>
        /// <returns></returns>
        public static List <List <Autodesk.DesignScript.Geometry.Point> > IntersectionPointsByCategory(Revit.Elements.Category category, Document document = null, bool refresh = false)
        {
            List <Revit.Elements.Element>         elList = new List <Revit.Elements.Element>();
            List <List <Revit.Elements.Element> > inList = new List <List <Revit.Elements.Element> >();

            List <List <Autodesk.DesignScript.Geometry.Point> > cPoints = new List <List <Autodesk.DesignScript.Geometry.Point> >();

            if (refresh)
            {
                BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString(), true);
                Document        doc       = DocumentManager.Instance.CurrentDBDocument;

                //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                ElementCategoryFilter    filter    = new ElementCategoryFilter(myCatEnum);
                ElementCategoryFilter    exclude   = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel);
                FilteredElementCollector excluded  = new FilteredElementCollector(doc).WherePasses(exclude);
                FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType();
                collector.Excluding(excluded.ToElementIds());

                foreach (Autodesk.Revit.DB.Element e in collector)
                {
                    DynaFunctions f = new DynaFunctions();


                    ElementIntersectsElementFilter interFiler = new ElementIntersectsElementFilter(e);
                    FilteredElementCollector       interElem  = new FilteredElementCollector(document).WherePasses(interFiler).WhereElementIsNotElementType();
                    if (interElem.GetElementCount() > 0)
                    {
                        List <Autodesk.Revit.DB.Solid> elGeoms = new List <Autodesk.Revit.DB.Solid>();
                        GeometryElement geomEl = e.get_Geometry(new Options());
                        foreach (GeometryObject geomObj in geomEl)
                        {
                            elGeoms.Add(geomObj as Autodesk.Revit.DB.Solid);
                        }

                        elList.Add(doc.GetElement(e.Id).ToDSType(true));
                        List <Autodesk.Revit.DB.Solid> iS = new List <Autodesk.Revit.DB.Solid>();
                        List <Autodesk.DesignScript.Geometry.Point> cPoint = new List <Autodesk.DesignScript.Geometry.Point>();
                        List <Autodesk.DesignScript.Geometry.Solid> iSS    = new List <Autodesk.DesignScript.Geometry.Solid>();
                        foreach (Autodesk.Revit.DB.Element el in interElem)
                        {
                            GeometryElement intEl = el.get_Geometry(new Options());
                            foreach (GeometryObject intObj in intEl)
                            {
                                iS.Add(intObj as Autodesk.Revit.DB.Solid);
                            }
                        }
                        foreach (Autodesk.Revit.DB.Solid s0 in elGeoms)
                        {
                            foreach (Autodesk.Revit.DB.Solid s1 in iS)
                            {
                                Autodesk.Revit.DB.Solid i = BooleanOperationsUtils.ExecuteBooleanOperation(s0, s1, BooleanOperationsType.Intersect);
                                if (i != null)
                                {
                                    iSS.Add(Revit.GeometryConversion.RevitToProtoSolid.ToProtoType(i));
                                    DisplayUnitType dt = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits;

                                    XYZ coord = new XYZ(f.convertToUnit(i.ComputeCentroid().X, dt), f.convertToUnit(i.ComputeCentroid().Y, dt), f.convertToUnit(i.ComputeCentroid().Z, dt));
                                    //XYZ coord = new XYZ(i.ComputeCentroid().X, i.ComputeCentroid().Y, i.ComputeCentroid().Z);
                                    Autodesk.DesignScript.Geometry.Point p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(coord.X, coord.Y, coord.Z);
                                    cPoint.Add(p);
                                }
                            }
                        }
                        cPoints.Add(cPoint);
                    }
                }
            }
            return(cPoints);
        }
Example #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="category"></param>
        /// <param name="refresh"></param>
        /// <returns></returns>
        public static List <List <Autodesk.DesignScript.Geometry.Solid> > IntersectionSolidsByCategory(Revit.Elements.Category category, Document document = null, bool refresh = false)
        {
            List <Revit.Elements.Element>         elList = new List <Revit.Elements.Element>();
            List <List <Revit.Elements.Element> > inList = new List <List <Revit.Elements.Element> >();

            List <List <Autodesk.DesignScript.Geometry.Solid> > interGeoms = new List <List <Autodesk.DesignScript.Geometry.Solid> >();


            if (refresh)
            {
                BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString(), true);
                Document        doc       = DocumentManager.Instance.CurrentDBDocument;

                //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                ElementCategoryFilter    filter    = new ElementCategoryFilter(myCatEnum);
                ElementCategoryFilter    exclude   = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel);
                FilteredElementCollector excluded  = new FilteredElementCollector(doc).WherePasses(exclude);
                FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType();
                collector.Excluding(excluded.ToElementIds());


                foreach (Autodesk.Revit.DB.Element e in collector)
                {
                    DynaFunctions f = new DynaFunctions();

                    ElementIntersectsElementFilter interFiler = new ElementIntersectsElementFilter(e);
                    FilteredElementCollector       interElem  = new FilteredElementCollector(document).WherePasses(interFiler).WhereElementIsNotElementType();
                    if (interElem.GetElementCount() > 0)
                    {
                        List <Autodesk.Revit.DB.Solid> elGeoms = new List <Autodesk.Revit.DB.Solid>();
                        GeometryElement geomEl = e.get_Geometry(new Options());
                        foreach (GeometryObject geomObj in geomEl)
                        {
                            elGeoms.Add(geomObj as Autodesk.Revit.DB.Solid);
                        }
                        List <Autodesk.Revit.DB.Solid> iS = new List <Autodesk.Revit.DB.Solid>();
                        List <Autodesk.DesignScript.Geometry.Solid> iSS = new List <Autodesk.DesignScript.Geometry.Solid>();
                        foreach (Autodesk.Revit.DB.Element el in interElem)
                        {
                            GeometryElement intEl = el.get_Geometry(new Options());
                            foreach (GeometryObject intObj in intEl)
                            {
                                iS.Add(intObj as Autodesk.Revit.DB.Solid);
                            }
                        }
                        foreach (Autodesk.Revit.DB.Solid s0 in elGeoms)
                        {
                            foreach (Autodesk.Revit.DB.Solid s1 in iS)
                            {
                                Autodesk.Revit.DB.Solid i = BooleanOperationsUtils.ExecuteBooleanOperation(s0, s1, BooleanOperationsType.Intersect);
                                if (i != null)
                                {
                                    Autodesk.Revit.DB.Solid bbox = f.CreateSolidFromBoundingBox(i);
                                    iSS.Add(Revit.GeometryConversion.RevitToProtoSolid.ToProtoType(i));
                                }
                            }
                        }
                        interGeoms.Add(iSS);
                    }
                }
            }
            return(interGeoms);
        }
Example #25
0
        public static List <Revit.Elements.Element> GetElementsByCategory(Revit.Elements.Element Room, Revit.Elements.Category category)
        {
            DB.Document doc        = DocumentManager.Instance.CurrentDBDocument;
            ElementId   categoryId = new ElementId(category.Id);

            DB.Category internalRevitCat                  = Autodesk.Revit.DB.Category.GetCategory(doc, categoryId);
            FilteredElementCollector collector            = new FilteredElementCollector(doc);
            List <DB.Element>        AllElementOfCategory = collector.OfCategoryId(internalRevitCat.Id).WhereElementIsNotElementType().ToElements().ToList();

            DB.Element                    _room  = (DB.Element)Room.InternalElement;
            DB.Architecture.Room          room   = _room as DB.Architecture.Room;
            List <Revit.Elements.Element> elems  = new List <Revit.Elements.Element>();
            List <Revit.Elements.Element> _elems = new List <Revit.Elements.Element>();

            foreach (DB.Element element in AllElementOfCategory)
            {
                DB.FamilyInstance familyInstance = (DB.FamilyInstance)element;
                LocationPoint     familyInstanceLocationPoint = familyInstance.Location as LocationPoint;
                XYZ point = familyInstanceLocationPoint.Point;
                if (room.IsPointInRoom(point))
                {
                    _elems.Add(element.ToDSType(true));
                }
            }
            return(_elems);
        }