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

        public static oM.Physical.Elements.Roof RoofFromRevit(this RoofBase roof, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            if (roof == null)
            {
                return(null);
            }

            settings = settings.DefaultIfNull();

            oM.Physical.Elements.Roof bHoMRoof = refObjects.GetValue <oM.Physical.Elements.Roof>(roof.Id);
            if (bHoMRoof != null)
            {
                return(bHoMRoof);
            }

            List <CurtainGrid> curtainGrids = roof.ICurtainGrids();

            if (curtainGrids.Count != 0)
            {
                bHoMRoof = roof.CurtainRoofFromRevit(settings, refObjects);
            }
            else
            {
                bHoMRoof = roof.SolidRoofFromRevit(settings, refObjects);
            }

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

            HostObjAttributes hostObjAttributes = roof.Document.GetElement(roof.GetTypeId()) as HostObjAttributes;
            string            materialGrade     = roof.MaterialGrade(settings);

            oM.Physical.Constructions.Construction construction = hostObjAttributes.ConstructionFromRevit(materialGrade, settings, refObjects);
            bHoMRoof.Construction = construction;

            bHoMRoof.Name = roof.FamilyTypeFullName();

            //Set identifiers, parameters & custom data
            bHoMRoof.SetIdentifiers(roof);
            bHoMRoof.CopyParameters(roof, settings.ParameterSettings);
            bHoMRoof.SetProperties(roof, settings.ParameterSettings);

            refObjects.AddOrReplace(roof.Id, bHoMRoof);
            return(bHoMRoof);
        }
Esempio n. 2
0
        /***************************************************/

        public static Element ToRevit(this oM.Physical.Elements.Roof roof, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            return(roof.ToRevitRoofBase(document, settings, refObjects));
        }
Esempio n. 3
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static RoofBase ToRevitRoofBase(this oM.Physical.Elements.Roof roof, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (roof == null || roof.Location == null || document == null)
            {
                return(null);
            }

            PlanarSurface planarSurface = roof.Location as PlanarSurface;

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

            RoofBase roofBase = refObjects.GetValue <RoofBase>(document, roof.BHoM_Guid);

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

            settings = settings.DefaultIfNull();

            RoofType roofType = roof.Construction?.ToRevitElementType(document, new List <BuiltInCategory> {
                BuiltInCategory.OST_Roofs
            }, settings, refObjects) as RoofType;

            if (roofType == null)
            {
                roofType = roof.ElementType(document, settings);
            }

            if (roofType == null)
            {
                Compute.ElementTypeNotFoundWarning(roof);
                return(null);
            }

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

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

            double elevation = level.Elevation.ToSI(UnitType.UT_Length);

            oM.Geometry.Plane plane = BH.Engine.Geometry.Create.Plane(BH.Engine.Geometry.Create.Point(0, 0, elevation), BH.Engine.Geometry.Create.Vector(0, 0, 1));

            ICurve     curve      = planarSurface.ExternalBoundary.IProject(plane);
            CurveArray curveArray = Create.CurveArray(curve.IToRevitCurves());

            ModelCurveArray modelCurveArray = new ModelCurveArray();

            roofBase = document.Create.NewFootPrintRoof(curveArray, level, roofType, out modelCurveArray);

            if (roofBase != null)
            {
                Parameter parameter = roofBase.get_Parameter(BuiltInParameter.ROOF_UPTO_LEVEL_PARAM);
                if (parameter != null)
                {
                    parameter.Set(ElementId.InvalidElementId);
                }

                List <oM.Geometry.Point> controlPoints = planarSurface.ExternalBoundary.IControlPoints();

                if (controlPoints != null && controlPoints.Count > 2)
                {
                    SlabShapeEditor slabShapeEditor = roofBase.SlabShapeEditor;
                    slabShapeEditor.ResetSlabShape();

                    foreach (oM.Geometry.Point point in controlPoints)
                    {
                        if (Math.Abs(point.Z - plane.Origin.Z) > settings.DistanceTolerance)
                        {
                            XYZ xyz = point.ToRevit();
                            slabShapeEditor.DrawPoint(xyz);
                        }
                    }
                }
            }

            roofBase.CheckIfNullPush(roof);
            if (roofBase == null)
            {
                return(null);
            }

            // Copy parameters from BHoM object to Revit element
            roofBase.CopyParameters(roof, settings);

            // Update the offset in case the level had been overwritten.
            double offset = 0;

            if (roofBase.LevelId.IntegerValue != level.Id.IntegerValue)
            {
                Level newLevel = document.GetElement(roofBase.LevelId) as Level;
                offset += (level.ProjectElevation - newLevel.ProjectElevation).ToSI(UnitType.UT_Length);
            }

            roofBase.SetParameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM, offset);

            refObjects.AddOrReplace(roof, roofBase);
            return(roofBase);
        }