Example #1
0
        /// <summary>
        /// Retrive family instance hosted in boundary elements
        /// This is the base function for Windows and Doors
        /// </summary>
        /// <param name="cat">The category of hosted elements</param>
        /// <returns></returns>
        private List<FamilyInstance> BoundaryFamilyInstance(DB.BuiltInCategory cat)
        {
            List<FamilyInstance> output = new List<FamilyInstance>();

            //the document of the room
            DB.Document doc = InternalElement.Document; // DocumentManager.Instance.CurrentDBDocument;

            //Find boundary elements and their associated document
            List<DB.ElementId> boundaryElements = new List<DB.ElementId>();
            List<DB.Document> boundaryDocuments = new List<DB.Document>();

            foreach (DB.BoundarySegment segment in InternalBoundarySegments)
            {
                DB.Element boundaryElement = doc.GetElement(segment.ElementId);
                if (boundaryElement.GetType() == typeof(DB.RevitLinkInstance))
                {
                    DB.RevitLinkInstance linkInstance = boundaryElement as DB.RevitLinkInstance;
                    boundaryDocuments.Add(linkInstance.GetLinkDocument());
                    boundaryElements.Add(segment.LinkElementId);
                }
                else
                {
                    boundaryDocuments.Add(doc);
                    boundaryElements.Add(segment.ElementId);
                }
            }

            // Create a category filter
            DB.ElementCategoryFilter filter = new DB.ElementCategoryFilter(cat);
            // Apply the filter to the elements in these documents,
            // Use shortcut WhereElementIsNotElementType() to find family instances in all boundary documents
            boundaryDocuments = boundaryDocuments.Distinct().ToList();
            List<DB.FamilyInstance> familyInstances = new List<DB.FamilyInstance>();
            foreach (DB.Document boundaryDocument in boundaryDocuments)
            {
                DB.FilteredElementCollector collector = new DB.FilteredElementCollector(boundaryDocument);
                familyInstances.AddRange(collector.WherePasses(filter).WhereElementIsNotElementType().ToElements().Cast<DB.FamilyInstance>().ToList());
            }

            //Find all family instance hosted on a boundary element
            IEnumerable<DB.FamilyInstance> boundaryFamilyInstances = familyInstances.Where(s => boundaryElements.Contains(s.Host.Id));

            //loop on these boundary family instance to find to and from room
            foreach (DB.FamilyInstance boundaryFamilyInstance in boundaryFamilyInstances)
            {
                DB.Phase familyInstancePhase = boundaryFamilyInstance.Document.GetElement(boundaryFamilyInstance.CreatedPhaseId) as DB.Phase;
                if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase) != null)
                {
                    if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase).Id == InternalRoom.Id)
                    {
                        output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance);
                        continue;
                    }
                }

                if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase) != null)
                {
                    if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase).Id == InternalRoom.Id)
                    {
                        output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance);
                    }
                }
            }

            output = output.Distinct().ToList();
            return output;
        }
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            if (!Parameters.Document.GetDataOrDefault(this, DA, "Document", out var doc))
            {
                return;
            }

            if (!Params.TryGetData(DA, "Design Option Set", out Types.DesignOptionSet set, x => x.IsValid))
            {
                return;
            }
            if (!Params.TryGetData(DA, "Name", out string name))
            {
                return;
            }
            if (!Params.TryGetData(DA, "Primary", out bool?primary))
            {
                return;
            }
            if (!Params.TryGetData(DA, "Filter", out DB.ElementFilter filter, x => x.IsValidObject))
            {
                return;
            }

            if (!(set?.Document is null || doc.Equals(set.Document)))
            {
                throw new System.ArgumentException("Wrong Document.", "Design Option Set");
            }

            using (var collector = new DB.FilteredElementCollector(doc))
            {
                var optionsCollector = collector.WherePasses(ElementFilter);

                if (filter is object)
                {
                    optionsCollector = optionsCollector.WherePasses(filter);
                }

                if (set is object && TryGetFilterElementIdParam(DB.BuiltInParameter.OPTION_SET_ID, set.Id, out var optionSetFilter))
                {
                    optionsCollector = optionsCollector.WherePasses(optionSetFilter);
                }

                if (name is object && TryGetFilterStringParam(DB.BuiltInParameter.OPTION_NAME, ref name, out var nameFilter))
                {
                    optionsCollector = optionsCollector.WherePasses(nameFilter);
                }

                var options = collector.Cast <DB.DesignOption>();

                if (primary.HasValue)
                {
                    options = options.Where(x => x.IsPrimary == primary.Value);
                }

                if (name is object)
                {
                    options = options.Where(x => x.get_Parameter(DB.BuiltInParameter.OPTION_NAME).AsString().IsSymbolNameLike(name));
                }

                if
                (
                    (set is null || set.Id == DB.ElementId.InvalidElementId) &&
                    (name is null || name == "Main Model") &&
                    primary != false
                )
                {
                    options = Enumerable.Repeat(default(DB.DesignOption), 1).Concat(options);
                }

                DA.SetDataList("Design Options", options.Select(x => new Types.DesignOption(x)));
            }
        }
Example #3
0
        /// <summary>
        /// Retrive family instance hosted in boundary elements
        /// This is the base function for Windows and Doors
        /// </summary>
        /// <param name="cat">The category of hosted elements</param>
        /// <returns></returns>
        private List <FamilyInstance> BoundaryFamilyInstance(DB.BuiltInCategory cat)
        {
            List <FamilyInstance> output = new List <FamilyInstance>();

            //the document of the room
            DB.Document doc = InternalElement.Document; // DocumentManager.Instance.CurrentDBDocument;

            //Find boundary elements and their associated document
            List <DB.ElementId> boundaryElements  = new List <DB.ElementId>();
            List <DB.Document>  boundaryDocuments = new List <DB.Document>();

            foreach (DB.BoundarySegment segment in InternalBoundarySegments)
            {
                DB.Element boundaryElement = doc.GetElement(segment.ElementId);
                if (boundaryElement.GetType() == typeof(DB.RevitLinkInstance))
                {
                    DB.RevitLinkInstance linkInstance = boundaryElement as DB.RevitLinkInstance;
                    boundaryDocuments.Add(linkInstance.GetLinkDocument());
                    boundaryElements.Add(segment.LinkElementId);
                }
                else
                {
                    boundaryDocuments.Add(doc);
                    boundaryElements.Add(segment.ElementId);
                }
            }

            // Create a category filter
            DB.ElementCategoryFilter filter = new DB.ElementCategoryFilter(cat);
            // Apply the filter to the elements in these documents,
            // Use shortcut WhereElementIsNotElementType() to find family instances in all boundary documents
            boundaryDocuments = boundaryDocuments.Distinct().ToList();
            List <DB.FamilyInstance> familyInstances = new List <DB.FamilyInstance>();

            foreach (DB.Document boundaryDocument in boundaryDocuments)
            {
                DB.FilteredElementCollector collector = new DB.FilteredElementCollector(boundaryDocument);
                familyInstances.AddRange(collector.WherePasses(filter).WhereElementIsNotElementType().ToElements().Cast <DB.FamilyInstance>().ToList());
            }

            //Find all family instance hosted on a boundary element
            IEnumerable <DB.FamilyInstance> boundaryFamilyInstances = familyInstances.Where(s => boundaryElements.Contains(s.Host.Id));

            //loop on these boundary family instance to find to and from room
            foreach (DB.FamilyInstance boundaryFamilyInstance in boundaryFamilyInstances)
            {
                DB.Phase familyInstancePhase = boundaryFamilyInstance.Document.GetElement(boundaryFamilyInstance.CreatedPhaseId) as DB.Phase;
                if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase) != null)
                {
                    if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase).Id == InternalRoom.Id)
                    {
                        output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance);
                        continue;
                    }
                }

                if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase) != null)
                {
                    if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase).Id == InternalRoom.Id)
                    {
                        output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance);
                    }
                }
            }

            output = output.Distinct().ToList();
            return(output);
        }
Example #4
0
        protected override void TrySolveInstance(IGH_DataAccess DA, DB.Document doc)
        {
            var  viewDiscipline     = default(DB.ViewDiscipline);
            var  _Discipline_       = Params.IndexOfInputParam("Discipline");
            bool nofilterDiscipline = (!DA.GetData(_Discipline_, ref viewDiscipline) && Params.Input[_Discipline_].Sources.Count == 0);

            var viewType = DB.ViewType.Undefined;

            DA.GetData("Type", ref viewType);

            string name = null;

            DA.GetData("Name", ref name);

            var  Template         = default(DB.View);
            var  _Template_       = Params.IndexOfInputParam("Template");
            bool nofilterTemplate = (!DA.GetData(_Template_, ref Template) && Params.Input[_Template_].DataType == GH_ParamData.@void);

            bool IsTemplate         = false;
            var  _IsTemplate_       = Params.IndexOfInputParam("IsTemplate");
            bool nofilterIsTemplate = (!DA.GetData(_IsTemplate_, ref IsTemplate) && Params.Input[_IsTemplate_].DataType == GH_ParamData.@void);

            bool IsAssembly         = false;
            var  _IsAssembly_       = Params.IndexOfInputParam("IsAssembly");
            bool nofilterIsAssembly = (!DA.GetData(_IsAssembly_, ref IsAssembly) && Params.Input[_IsAssembly_].DataType == GH_ParamData.@void);

            bool IsPrintable         = false;
            var  _IsPrintable_       = Params.IndexOfInputParam("IsPrintable");
            bool nofilterIsPrintable = (!DA.GetData(_IsPrintable_, ref IsPrintable) && Params.Input[_IsPrintable_].DataType == GH_ParamData.@void);

            DB.ElementFilter filter = null;
            DA.GetData("Filter", ref filter);

            using (var collector = new DB.FilteredElementCollector(doc))
            {
                var viewsCollector = collector.WherePasses(ElementFilter);

                if (filter is object)
                {
                    viewsCollector = viewsCollector.WherePasses(filter);
                }

                if (!nofilterDiscipline && TryGetFilterIntegerParam(DB.BuiltInParameter.VIEW_DISCIPLINE, (int)viewDiscipline, out var viewDisciplineFilter))
                {
                    viewsCollector = viewsCollector.WherePasses(viewDisciplineFilter);
                }

                if (TryGetFilterStringParam(DB.BuiltInParameter.VIEW_NAME, ref name, out var viewNameFilter))
                {
                    viewsCollector = viewsCollector.WherePasses(viewNameFilter);
                }

                if (!nofilterTemplate && TryGetFilterElementIdParam(DB.BuiltInParameter.VIEW_TEMPLATE, Template?.Id ?? DB.ElementId.InvalidElementId, out var templateFilter))
                {
                    viewsCollector = viewsCollector.WherePasses(templateFilter);
                }

                var views = collector.Cast <DB.View>();

                if (!nofilterIsTemplate)
                {
                    views = views.Where((x) => x.IsTemplate == IsTemplate);
                }

                if (!nofilterIsAssembly)
                {
                    views = views.Where((x) => x.IsAssemblyView == IsAssembly);
                }

                if (!nofilterIsPrintable)
                {
                    views = views.Where((x) => x.CanBePrinted == IsPrintable);
                }

                if (viewType != DB.ViewType.Undefined)
                {
                    views = views.Where((x) => x.ViewType == viewType);
                }

                if (name is object)
                {
                    views = views.Where(x => x.Name.IsSymbolNameLike(name));
                }

                DA.SetDataList("Views", views);
            }
        }