예제 #1
0
        /***************************************************/

        public static ICurve LocationCurveFraming(this FamilyInstance familyInstance, RevitSettings settings = null)
        {
            settings = settings.DefaultIfNull();

            ICurve curve = (familyInstance.Location as LocationCurve)?.Curve?.IFromRevit();

            if (curve == null || (!(curve is NurbsCurve) && curve.ILength() <= settings.DistanceTolerance))
            {
                familyInstance.FramingCurveNotFoundWarning();
                return(null);
            }

            BH.oM.Geometry.Line line = curve as BH.oM.Geometry.Line;
            if (line == null)
            {
                familyInstance.NonLinearFramingOffsetWarning();
                return(curve);
            }

            Transform transform = familyInstance.GetTotalTransform();
            Vector    dir       = line.Direction();

            BH.oM.Geometry.Plane startPlane = new oM.Geometry.Plane {
                Origin = line.Start, Normal = dir
            };
            BH.oM.Geometry.Plane endPlane = new oM.Geometry.Plane {
                Origin = line.End, Normal = dir
            };
            BH.oM.Geometry.Line transformedLine = BH.Engine.Geometry.Create.Line(transform.Origin.PointFromRevit(), transform.BasisX.VectorFromRevit());
            line = new BH.oM.Geometry.Line {
                Start = transformedLine.PlaneIntersection(startPlane, true), End = transformedLine.PlaneIntersection(endPlane, true)
            };

            double startExtension = familyInstance.LookupParameterDouble(BuiltInParameter.START_EXTENSION);

            if (!double.IsNaN(startExtension))
            {
                line.Start = line.Start - dir * startExtension;
            }

            double endExtension = familyInstance.LookupParameterDouble(BuiltInParameter.END_EXTENSION);

            if (!double.IsNaN(endExtension))
            {
                line.End = line.End + dir * endExtension;
            }

            return(line);
        }
예제 #2
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);
        }
예제 #3
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static IFramingElementProperty FramingElementProperty(this FamilyInstance familyInstance, RevitSettings settings, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            if (familyInstance == null || familyInstance.Symbol == null)
            {
                return(null);
            }

            ConstantFramingProperty framingProperty = refObjects.GetValue <ConstantFramingProperty>(familyInstance.Id);

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

            // Convert the material to BHoM.
            ElementId structuralMaterialId = familyInstance.StructuralMaterialId;

            if (structuralMaterialId.IntegerValue < 0)
            {
                structuralMaterialId = familyInstance.Symbol.LookupParameterElementId(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);
            }

            Material revitMaterial = familyInstance.Document.GetElement(structuralMaterialId) as Material;

            if (revitMaterial == null)
            {
                revitMaterial = familyInstance.Category.Material;
            }

            string materialGrade = familyInstance.MaterialGrade(settings);

            BH.oM.Physical.Materials.Material material = revitMaterial.MaterialFromRevit(materialGrade, settings, refObjects);

            // If Revit material is null, rename the BHoM material based on material type of framing family.
            if (material != null && revitMaterial == null)
            {
                material.Name = String.Format("Unknown {0} Material", familyInstance.StructuralMaterialType);
                material.Properties.Add(familyInstance.StructuralMaterialType.EmptyMaterialFragment(materialGrade));
            }

            IProfile profile = familyInstance.Symbol.ProfileFromRevit(settings, refObjects);

            if (profile == null)
            {
                familyInstance.Symbol.NotConvertedWarning();
            }

            if (familyInstance.Mirrored)
            {
                if (profile is FreeFormProfile)
                {
                    BH.oM.Geometry.Plane mirror = new oM.Geometry.Plane {
                        Normal = BH.oM.Geometry.Vector.XAxis
                    };
                    profile = BH.Engine.Spatial.Create.FreeFormProfile(profile.Edges.Select(x => x.IMirror(mirror)));
                }
                else if (profile is AngleProfile)
                {
                    AngleProfile angle = ((AngleProfile)profile);
                    profile = BH.Engine.Spatial.Create.AngleProfile(angle.Height, angle.Width, angle.WebThickness, angle.FlangeThickness, angle.RootRadius, angle.ToeRadius, true, false);
                }
                else if (profile is ChannelProfile)
                {
                    ChannelProfile channel = ((ChannelProfile)profile);
                    profile = BH.Engine.Spatial.Create.ChannelProfile(channel.Height, channel.FlangeWidth, channel.WebThickness, channel.FlangeThickness, channel.RootRadius, channel.ToeRadius, true);
                }
            }

            double rotation = familyInstance.OrientationAngle(settings);

            framingProperty = BH.Engine.Physical.Create.ConstantFramingProperty(profile, material, rotation, familyInstance.Symbol.Name);

            //Set identifiers, parameters & custom data
            framingProperty.SetIdentifiers(familyInstance.Symbol);
            framingProperty.CopyParameters(familyInstance.Symbol, settings.ParameterSettings);
            framingProperty.SetProperties(familyInstance.Symbol, settings.ParameterSettings);

            refObjects.AddOrReplace(familyInstance.Id, framingProperty);
            return(framingProperty);
        }
예제 #4
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static Plane ToRevit(this oM.Geometry.Plane plane)
        {
            return(Plane.CreateByNormalAndOrigin(plane.Normal.ToRevit(), plane.Origin.ToRevit()));
        }
예제 #5
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static Floor ToRevitFloor(this oM.Physical.Elements.Floor floor, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (floor == null || floor.Construction == null || document == null)
            {
                return(null);
            }

            Floor revitFloor = refObjects.GetValue <Floor>(document, floor.BHoM_Guid);

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

            PlanarSurface planarSurface = floor.Location as PlanarSurface;

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

            settings = settings.DefaultIfNull();

            FloorType floorType = floor.Construction?.ToRevitElementType(document, new List <BuiltInCategory> {
                BuiltInCategory.OST_Floors
            }, settings, refObjects) as FloorType;

            if (floorType == null)
            {
                floorType = floor.ElementType(document, settings);
            }

            if (floorType == null)
            {
                Compute.ElementTypeNotFoundWarning(floor);
                return(null);
            }

            double bottomElevation = floor.Location.IBounds().Min.Z;
            Level  level           = document.LevelBelow(bottomElevation.FromSI(UnitType.UT_Length), settings);

            oM.Geometry.Plane sketchPlane = new oM.Geometry.Plane {
                Origin = new BH.oM.Geometry.Point {
                    Z = bottomElevation
                }, Normal = Vector.ZAxis
            };
            ICurve     curve      = planarSurface.ExternalBoundary.IProject(sketchPlane);
            CurveArray curveArray = Create.CurveArray(curve.IToRevitCurves());

            BH.oM.Geometry.Plane slabPlane = planarSurface.FitPlane();
            if (1 - Math.Abs(Vector.ZAxis.DotProduct(slabPlane.Normal)) <= settings.AngleTolerance)
            {
                revitFloor = document.Create.NewFloor(curveArray, floorType, level, true);
            }
            else
            {
                Vector normal = slabPlane.Normal;
                if (normal.Z < 0)
                {
                    normal = -slabPlane.Normal;
                }

                double angle = normal.Angle(Vector.ZAxis);
                double tan   = Math.Tan(angle);

                XYZ dir = normal.Project(oM.Geometry.Plane.XY).ToRevit().Normalize();
                BH.oM.Geometry.Line ln = slabPlane.PlaneIntersection(sketchPlane);
                XYZ start = ln.ClosestPoint(curveArray.get_Item(0).GetEndPoint(0).PointFromRevit(), true).ToRevit();
                Autodesk.Revit.DB.Line line = Autodesk.Revit.DB.Line.CreateBound(start, start + dir);

                revitFloor = document.Create.NewSlab(curveArray, level, line, -tan, true);
                revitFloor.SetParameter(BuiltInParameter.ELEM_TYPE_PARAM, floorType.Id);
            }

            revitFloor.CheckIfNullPush(floor);
            if (revitFloor == null)
            {
                return(null);
            }

            document.Regenerate();

            if (planarSurface.InternalBoundaries != null)
            {
                foreach (ICurve hole in planarSurface.InternalBoundaries)
                {
                    document.Create.NewOpening(revitFloor, Create.CurveArray(hole.IProject(slabPlane).IToRevitCurves()), true);
                }
            }

            foreach (BH.oM.Physical.Elements.IOpening opening in floor.Openings)
            {
                PlanarSurface openingLocation = opening.Location as PlanarSurface;
                if (openingLocation == null)
                {
                    BH.Engine.Reflection.Compute.RecordWarning(String.Format("Conversion of a floor opening to Revit failed because its location is not a planar surface. Floor BHoM_Guid: {0}, Opening BHoM_Guid: {1}", floor.BHoM_Guid, opening.BHoM_Guid));
                    continue;
                }

                document.Create.NewOpening(revitFloor, Create.CurveArray(openingLocation.ExternalBoundary.IToRevitCurves()), true);

                if (!(opening is BH.oM.Physical.Elements.Void))
                {
                    BH.Engine.Reflection.Compute.RecordWarning(String.Format("Revit allows only void openings in floors, therefore the BHoM opening of type {0} has been converted to a void opening. Floor BHoM_Guid: {1}, Opening BHoM_Guid: {2}", opening.GetType().Name, floor.BHoM_Guid, opening.BHoM_Guid));
                }
            }

            double offset = revitFloor.LookupParameterDouble(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM);

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

            // Update the offset in case the level had been overwritten.
            if (revitFloor.LevelId.IntegerValue != level.Id.IntegerValue)
            {
                Level newLevel = document.GetElement(revitFloor.LevelId) as Level;
                offset += (level.ProjectElevation - newLevel.ProjectElevation).ToSI(UnitType.UT_Length);
            }

            revitFloor.SetParameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM, offset);

            refObjects.AddOrReplace(floor, revitFloor);
            return(revitFloor);
        }