Esempio n. 1
0
        /***************************************************/
        /****              Private Methods              ****/
        /***************************************************/

        private static List <ISurface> OpeningSurfaces_HostDocument(this FamilyInstance familyInstance, List <HostObject> hosts, Element parentElement, RevitSettings settings = null)
        {
            List <ISurface> surfaces = new List <ISurface>();

            if (parentElement != null) // Indicates element is a nested instance and needs different approach to extract location
            {
                Document doc = familyInstance.Document;

                Transaction t = new Transaction(doc);

                t.Start("Temp Delete Inserts");
                List <ElementId> inserts = hosts.SelectMany(x => x.FindInserts(true, true, true, true)).Distinct().Where(x => x.IntegerValue != -1).ToList();

                // Create dummy instance of nested element with matching parameters
                LocationPoint locPt         = familyInstance.Location as LocationPoint;
                Element       dummyInstance = doc.Create.NewFamilyInstance(locPt.Point, familyInstance.Symbol, hosts.First() as Element, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                IEnumerable <BuiltInParameter> paramsToSkip = new List <BuiltInParameter> {
                    BuiltInParameter.INSTANCE_HEAD_HEIGHT_PARAM, BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM
                };
                familyInstance.CopyParameters(dummyInstance, paramsToSkip);

                doc.Delete(inserts);
                doc.Regenerate();

                return(GetOpeningGeometry(t, doc, hosts, inserts, familyInstance, settings));
            }
            else if (hosts.Count != 0)
            {
                Document    doc = familyInstance.Document;
                Transaction t   = new Transaction(doc);

                t.Start("Temp Delete Inserts");

                List <ElementId> inserts = hosts.SelectMany(x => x.FindInserts(true, true, true, true)).Distinct().Where(x => x.IntegerValue != familyInstance.Id.IntegerValue).ToList();
                doc.Delete(inserts);
                doc.Regenerate();

                try
                {
                    inserts.Add(familyInstance.Id);
                }
                catch
                {
                }

                return(GetOpeningGeometry(t, doc, hosts, inserts, familyInstance, settings));
            }
            else
            {
                return(familyInstance.OpeningSurfaces_Curtain());
            }
        }
Esempio n. 2
0
        /***************************************************/

        public static FamilyInstance ToRevitFamilyInstance(this IFramingElement framingElement, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (framingElement == null || document == null)
            {
                return(null);
            }

            FamilyInstance familyInstance = refObjects.GetValue <FamilyInstance>(document, framingElement.BHoM_Guid);

            if (familyInstance != null)
            {
                return(familyInstance);
            }

            settings = settings.DefaultIfNull();

            if (framingElement.Location == null)
            {
                BH.Engine.Reflection.Compute.RecordError(String.Format("Revit element could not be created because the driving curve of a BHoM object is null. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            if (!framingElement.Location.IIsPlanar())
            {
                BH.Engine.Reflection.Compute.RecordError(string.Format("Revit framing does only support planar curves, element could not be created. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            Curve revitCurve = framingElement.Location.IToRevit();

            if (revitCurve == null)
            {
                BH.Engine.Reflection.Compute.RecordError(string.Format("Revit element could not be created because of curve conversion issues. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            Level level = document.LevelBelow(framingElement.Location, settings);

            FamilySymbol familySymbol = framingElement.Property.ToRevitElementType(document, framingElement.BuiltInCategories(document), settings, refObjects);

            if (familySymbol == null)
            {
                familySymbol = framingElement.ElementType(document, settings) as FamilySymbol;
            }

            if (familySymbol == null)
            {
                Compute.ElementTypeNotFoundWarning(framingElement);
                return(null);
            }

            FamilyPlacementType familyPlacementType = familySymbol.Family.FamilyPlacementType;

            if (familyPlacementType != FamilyPlacementType.CurveBased && familyPlacementType != FamilyPlacementType.CurveBasedDetail && familyPlacementType != FamilyPlacementType.CurveDrivenStructural && familyPlacementType != FamilyPlacementType.TwoLevelsBased)
            {
                Compute.InvalidFamilyPlacementTypeError(framingElement, familySymbol);
                return(null);
            }

            if (framingElement is Beam)
            {
                familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Beam);
            }
            else if (framingElement is Bracing || framingElement is Cable)
            {
                familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Brace);
            }
            else
            {
                familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming);
            }

            document.Regenerate();

            familyInstance.CheckIfNullPush(framingElement);
            if (familyInstance == null)
            {
                return(null);
            }

            oM.Physical.FramingProperties.ConstantFramingProperty barProperty = framingElement.Property as oM.Physical.FramingProperties.ConstantFramingProperty;
            if (barProperty != null)
            {
                //TODO: if the material does not get assigned an error should be thrown?
                if (barProperty.Material != null)
                {
                    Material material = document.GetElement(new ElementId(BH.Engine.Adapters.Revit.Query.ElementId(barProperty.Material))) as Material;
                    if (material != null)
                    {
                        Parameter param = familyInstance.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);
                        if (param != null && param.HasValue && !param.IsReadOnly)
                        {
                            familyInstance.StructuralMaterialId = material.Id;
                        }
                        else
                        {
                            BH.Engine.Reflection.Compute.RecordWarning(string.Format("The BHoM material has been correctly converted, but the property could not be assigned to the Revit element. ElementId: {0}", familyInstance.Id));
                        }
                    }
                }
            }

            //Set the insertion point to centroid.
            Parameter zJustification = familyInstance.get_Parameter(BuiltInParameter.Z_JUSTIFICATION);

            if (zJustification != null && !zJustification.IsReadOnly)
            {
                zJustification.Set((int)Autodesk.Revit.DB.Structure.ZJustification.Origin);
            }

            familyInstance.CopyParameters(framingElement, settings);
            familyInstance.SetLocation(framingElement, settings);

            if (familyInstance.StructuralMaterialType != StructuralMaterialType.Concrete && familyInstance.StructuralMaterialType != StructuralMaterialType.PrecastConcrete)
            {
                StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 0);
                StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 1);
            }

            refObjects.AddOrReplace(framingElement, familyInstance);
            return(familyInstance);
        }
Esempio n. 3
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static FamilyInstance ToRevitFamilyInstance(this Column framingElement, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (framingElement == null || document == null)
            {
                return(null);
            }

            FamilyInstance familyInstance = refObjects.GetValue <FamilyInstance>(document, framingElement.BHoM_Guid);

            if (familyInstance != null)
            {
                return(familyInstance);
            }

            settings = settings.DefaultIfNull();

            if (framingElement.Location == null)
            {
                BH.Engine.Reflection.Compute.RecordError(String.Format("Revit element could not be created because the driving curve of a BHoM object is null. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            if (framingElement.Location as BH.oM.Geometry.Line == null)
            {
                BH.Engine.Reflection.Compute.RecordError(string.Format("Revit does only support line-based columns. Try pushing your element as a beam instead. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            if (((BH.oM.Geometry.Line)framingElement.Location).Start.Z >= ((BH.oM.Geometry.Line)framingElement.Location).End.Z)
            {
                BH.Engine.Reflection.Compute.RecordError(string.Format("Start point of Revit columns need to have lower elevation than the end point. Have a look at flipping your location curves. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            Level level = document.LevelBelow(framingElement.Location, settings);

            if (level == null)
            {
                return(null);
            }

            Line columnLine = framingElement.Location.IToRevit() as Line;

            FamilySymbol familySymbol = framingElement.Property.ToRevitElementType(document, framingElement.BuiltInCategories(document), settings, refObjects);

            if (familySymbol == null)
            {
                familySymbol = framingElement.ElementType(document, settings) as FamilySymbol;
            }

            if (familySymbol == null)
            {
                Compute.ElementTypeNotFoundWarning(framingElement);
                return(null);
            }

            FamilyPlacementType familyPlacementType = familySymbol.Family.FamilyPlacementType;

            if (familyPlacementType != FamilyPlacementType.CurveBased && familyPlacementType != FamilyPlacementType.CurveBasedDetail && familyPlacementType != FamilyPlacementType.CurveDrivenStructural && familyPlacementType != FamilyPlacementType.TwoLevelsBased)
            {
                Compute.InvalidFamilyPlacementTypeError(framingElement, familySymbol);
                return(null);
            }

            familyInstance = document.Create.NewFamilyInstance(columnLine, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Column);
            document.Regenerate();

            familyInstance.CheckIfNullPush(framingElement);
            if (familyInstance == null)
            {
                return(null);
            }

            oM.Physical.FramingProperties.ConstantFramingProperty barProperty = framingElement.Property as oM.Physical.FramingProperties.ConstantFramingProperty;
            if (barProperty != null)
            {
                //TODO: if the material does not get assigned an error should be thrown?
                if (barProperty.Material != null)
                {
                    Autodesk.Revit.DB.Material material = document.GetElement(new ElementId(BH.Engine.Adapters.Revit.Query.ElementId(barProperty.Material))) as Autodesk.Revit.DB.Material;
                    if (material != null)
                    {
                        Parameter param = familyInstance.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);
                        if (param != null && param.HasValue && !param.IsReadOnly)
                        {
                            familyInstance.StructuralMaterialId = material.Id;
                        }
                        else
                        {
                            BH.Engine.Reflection.Compute.RecordWarning(string.Format("The BHoM material has been correctly converted, but the property could not be assigned to the Revit element. ElementId: {0}", familyInstance.Id));
                        }
                    }
                }
            }

            // Make sure the top is above base, otherwise Revit will complain for no reason.
            familyInstance.get_Parameter((BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM)).Set(-1e+3);
            familyInstance.get_Parameter((BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM)).Set(1e+3);

            familyInstance.CopyParameters(framingElement, settings);
            familyInstance.SetLocation(framingElement, settings);

            refObjects.AddOrReplace(framingElement, familyInstance);
            return(familyInstance);
        }
Esempio n. 4
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static ISurface OpeningSurface(this FamilyInstance familyInstance, HostObject host = null, RevitSettings settings = null)
        {
            if (familyInstance == null)
            {
                return(null);
            }

            BoundingBoxXYZ bbox = familyInstance.get_BoundingBox(null);

            if (bbox == null)
            {
                return(null);
            }

            // Get parent element if this family instance is a nested instance
            Element parentElem = familyInstance.SuperComponent;
            int     parentId   = -1;

            if (parentElem != null)
            {
                parentId = familyInstance.SuperComponent.Id.IntegerValue;
            }

            settings = settings.DefaultIfNull();
            List <HostObject> hosts;

            if (host != null)
            {
                hosts = new List <HostObject> {
                    host
                }
            }
            ;
            else
            {
                BoundingBoxIntersectsFilter bbif = new BoundingBoxIntersectsFilter(new Outline(bbox.Min, bbox.Max));
                hosts = new FilteredElementCollector(familyInstance.Document).OfClass(typeof(HostObject)).WherePasses(bbif).Cast <HostObject>().ToList();
                hosts = hosts.Where(x => x.FindInserts(true, true, true, true).Any(y => (y.IntegerValue == familyInstance.Id.IntegerValue) || (y.IntegerValue == parentId))).ToList();
            }

            List <ISurface> surfaces = new List <ISurface>();

            if (parentElem != null) // Indicates element is a nested instance and needs different approach to extract location
            {
                Document    doc = familyInstance.Document;
                Transaction t   = new Transaction(doc);

                t.Start("Temp Delete Inserts");
                List <ElementId> inserts = hosts.SelectMany(x => x.FindInserts(true, true, true, true)).Distinct().Where(x => x.IntegerValue != -1).ToList();

                // Create dummy instance of nested element with matching parameters
                LocationPoint locPt         = familyInstance.Location as LocationPoint;
                Element       dummyInstance = doc.Create.NewFamilyInstance(locPt.Point, familyInstance.Symbol, hosts.First() as Element, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                IEnumerable <BuiltInParameter> paramsToSkip = new List <BuiltInParameter> {
                    BuiltInParameter.INSTANCE_HEAD_HEIGHT_PARAM, BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM
                };
                familyInstance.CopyParameters(dummyInstance, paramsToSkip);

                doc.Delete(inserts);
                doc.Regenerate();

                surfaces = GetOpeningGeometry(t, doc, hosts, inserts, familyInstance, settings);
            }

            else if (hosts.Count == 0)
            {
                HostObject curtainHost = familyInstance.Host as HostObject;
                if (curtainHost == null)
                {
                    return(null);
                }

                List <CurtainGrid> curtainGrids = curtainHost.ICurtainGrids();
                if (curtainGrids.Count != 0)
                {
                    foreach (CurtainGrid cg in curtainGrids)
                    {
                        List <ElementId>   ids   = cg.GetPanelIds().ToList();
                        List <CurtainCell> cells = cg.GetCurtainCells().ToList();
                        if (ids.Count != cells.Count)
                        {
                            return(null);
                        }

                        for (int i = 0; i < ids.Count; i++)
                        {
                            if (ids[i].IntegerValue == familyInstance.Id.IntegerValue)
                            {
                                foreach (PolyCurve curve in cells[i].CurveLoops.FromRevit())
                                {
                                    PlanarSurface surface = new PlanarSurface(curve, null);
                                    if (surface == null)
                                    {
                                        return(null);
                                    }

                                    surfaces.Add(surface);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Document    doc = familyInstance.Document;
                Transaction t   = new Transaction(doc);

                t.Start("Temp Delete Inserts");

                List <ElementId> inserts = hosts.SelectMany(x => x.FindInserts(true, true, true, true)).Distinct().Where(x => x.IntegerValue != familyInstance.Id.IntegerValue).ToList();
                doc.Delete(inserts);
                doc.Regenerate();

                try
                {
                    inserts.Add(familyInstance.Id);
                }
                catch
                {
                }

                surfaces = GetOpeningGeometry(t, doc, hosts, inserts, familyInstance, settings);
            }

            if (surfaces.Count == 0)
            {
                return(null);
            }
            else if (surfaces.Count == 1)
            {
                return(surfaces[0]);
            }
            else
            {
                return new PolySurface {
                           Surfaces = surfaces
                }
            };
        }