Пример #1
0
        public List <ApplicationPlaceholderObject> RoofToNative(Roof speckleRoof)
        {
            if (speckleRoof.outline == null)
            {
                throw new Speckle.Core.Logging.SpeckleException("Only outline based Floor are currently supported.");
            }

            DB.RoofBase revitRoof = null;
            DB.Level    level     = null;
            var         outline   = CurveToNative(speckleRoof.outline);

            var speckleRevitRoof = speckleRoof as RevitRoof;

            if (speckleRevitRoof != null)
            {
                level = LevelToNative(speckleRevitRoof.level);
            }
            else
            {
                level = LevelToNative(LevelFromCurve(outline.get_Item(0)));
            }

            var roofType = GetElementType <RoofType>((Base)speckleRoof);

            var docObj = GetExistingElementByApplicationId(((Base)speckleRoof).applicationId);

            if (docObj != null)
            {
                Doc.Delete(docObj.Id);
            }

            switch (speckleRoof)
            {
            case RevitExtrusionRoof speckleExtrusionRoof:
            {
                var            referenceLine = LineToNative(speckleExtrusionRoof.referenceLine);
                var            norm          = GetPerpendicular(referenceLine.GetEndPoint(0) - referenceLine.GetEndPoint(1)).Negate();
                ReferencePlane plane         = Doc.Create.NewReferencePlane(referenceLine.GetEndPoint(0),
                                                                            referenceLine.GetEndPoint(1),
                                                                            norm,
                                                                            Doc.ActiveView);
                //create floor without a type
                var start = ScaleToNative(speckleExtrusionRoof.start, speckleExtrusionRoof.units);
                var end   = ScaleToNative(speckleExtrusionRoof.end, speckleExtrusionRoof.units);
                revitRoof = Doc.Create.NewExtrusionRoof(outline, plane, level, roofType, start, end);
                break;
            }

            case RevitFootprintRoof speckleFootprintRoof:
            {
                ModelCurveArray curveArray         = new ModelCurveArray();
                var             revitFootprintRoof = Doc.Create.NewFootPrintRoof(outline, level, roofType, out curveArray);
                var             poly          = speckleFootprintRoof.outline as Polycurve;
                bool            hasSlopedSide = false;
                if (poly != null)
                {
                    for (var i = 0; i < curveArray.Size; i++)
                    {
                        var isSloped   = ((Base)poly.segments[i])["isSloped"] as bool?;
                        var slopeAngle = ((Base)poly.segments[i])["slopeAngle"] as double?;
                        var offset     = ((Base)poly.segments[i])["offset"] as double?;

                        if (isSloped != null)
                        {
                            revitFootprintRoof.set_DefinesSlope(curveArray.get_Item(i), isSloped == true);
                            if (slopeAngle != null && isSloped == true)
                            {
                                revitFootprintRoof.set_SlopeAngle(curveArray.get_Item(i), (double)slopeAngle);
                                hasSlopedSide = true;
                            }
                        }

                        if (offset != null)
                        {
                            revitFootprintRoof.set_Offset(curveArray.get_Item(i), (double)offset);
                        }
                    }
                }

                //this is for schema builder specifically
                //if no roof edge has a slope defined but a slope angle is defined on the roof
                //set each edge to have that slope
                if (!hasSlopedSide && speckleFootprintRoof.slope != null)
                {
                    for (var i = 0; i < curveArray.Size; i++)
                    {
                        revitFootprintRoof.set_DefinesSlope(curveArray.get_Item(i), true);
                    }
                    TrySetParam(revitFootprintRoof, BuiltInParameter.ROOF_SLOPE, (double)speckleFootprintRoof.slope);
                }

                if (speckleFootprintRoof.cutOffLevel != null)
                {
                    var cutOffLevel = LevelToNative(speckleFootprintRoof.cutOffLevel);
                    TrySetParam(revitFootprintRoof, BuiltInParameter.ROOF_UPTO_LEVEL_PARAM, cutOffLevel);
                }

                revitRoof = revitFootprintRoof;
                break;
            }

            default:
                ConversionErrors.Add(new Error("Cannot create Roof", "Roof type not supported"));
                throw new Speckle.Core.Logging.SpeckleException("Roof type not supported");
            }

            Doc.Regenerate();

            try
            {
                CreateVoids(revitRoof, speckleRoof);
            }
            catch (Exception ex)
            {
                ConversionErrors.Add(new Error($"Could not create openings in roof {speckleRoof.applicationId}", ex.Message));
            }

            if (speckleRevitRoof != null)
            {
                SetInstanceParameters(revitRoof, speckleRevitRoof);
            }

            var placeholders = new List <ApplicationPlaceholderObject>()
            {
                new ApplicationPlaceholderObject {
                    applicationId = speckleRevitRoof.applicationId, ApplicationGeneratedId = revitRoof.UniqueId, NativeObject = revitRoof
                }
            };

            var hostedElements = SetHostedElements(speckleRoof, revitRoof);

            placeholders.AddRange(hostedElements);

            return(placeholders);
        }
Пример #2
0
        /// <summary>
        /// Add a roof over the rectangular profile of the walls we created earlier.
        /// </summary>
        public static void AddRoof(Document rvtDoc, List <Wall> walls)
        {
            // Hard coding the roof type we will use.
            // e.g., "Basic Roof: Generic - 400mm"
            const string roofFamilyName        = "Basic Roof";
            const string roofTypeName          = Util.Constant.RoofTypeName;
            const string roofFamilyAndTypeName = roofFamilyName + ": " + roofTypeName;

            // Find the roof type
            RoofType roofType =
                ElementFiltering.FindFamilyType(
                    rvtDoc, typeof(RoofType), roofFamilyName, roofTypeName, null
                    ) as RoofType;

            if (roofType == null)
            {
                TaskDialog.Show(
                    "Add roof", "Cannot find (" + roofFamilyAndTypeName +
                    "). Maybe you use a different template? Try with DefaultMetric.rte.");
            }

            // Wall thickness to adjust the footprint of the walls
            // to the outer most lines.
            // Note: this may not be the best way.
            // but we will live with this for this exercise.
            //Dim wallThickness As Double = _
            //walls(0).WallType.CompoundStructure.Layers.Item(0).Thickness() ' 2011
            double wallThickness = walls[0].WallType.GetCompoundStructure().GetLayers()[0].Width;

            // 2012
            double     dt  = wallThickness / 2.0;
            List <XYZ> dts = new List <XYZ>(5);

            dts.Add(new XYZ(-dt, -dt, 0.0));
            dts.Add(new XYZ(dt, -dt, 0.0));
            dts.Add(new XYZ(dt, dt, 0.0));
            dts.Add(new XYZ(-dt, dt, 0.0));
            dts.Add(dts[0]);

            // Set the profile from four walls
            CurveArray footPrint = new CurveArray();

            for (int i = 0; i <= 3; i++)
            {
                LocationCurve locCurve = (LocationCurve)walls[i].Location;
                XYZ           pt1      = locCurve.Curve.GetEndPoint(0) + dts[i];
                XYZ           pt2      = locCurve.Curve.GetEndPoint(1) + dts[i + 1];
                Line          line     = Line.CreateBound(pt1, pt2);
                footPrint.Append(line);
            }

            // Get the level2 from the wall.

            ElementId idLevel2 = walls[0].get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId();

            //Level level2 = (Level)_doc.get_Element(idLevel2); // 2012
            Level level2 = rvtDoc.GetElement(idLevel2) as Level; // since 2013

            // Footprint to model curve mapping.

            ModelCurveArray mapping = new ModelCurveArray();

            // Create a roof.

            FootPrintRoof aRoof = rvtDoc.Create.NewFootPrintRoof(
                footPrint, level2, roofType, out mapping);

            // Set the slope.

            /////////////////////////////////////////////////
            ///new mapping
            /////////////////////////////////////////////////

            LocationCurve wallCurv1 = (LocationCurve)walls[1].Location;
            // set the gable roof slope

            ModelCurveArray mappingNew  = new ModelCurveArray();
            ModelCurve      gableCurve1 = mapping.get_Item(1);
            ModelCurve      gableCurve2 = mapping.get_Item(3);

            double a = wallCurv1.Curve.Length / 2.00;
            double b = 4.00;


            //double angleB = Math.Truncate( Math.Acos((c * c + a * a - b * b)/(2 * c * a)) * 100 ) / 100; // Math.PI * 180;

            /* The value is a 'slope' measurement. For example, 0.5 is one unit of rise for each 2 units of run.
             * this creates a slope of 26.57 degrees
             * (the arctangent of 0.5)
             * double angleBDegrees = angleBRadians * 180 / Math.PI;
             * double c = Math.Truncate(Math.Sqrt(a * a + b * b) * 100) / 100;
             * double c = Math.Sqrt(a * a + b * b);
             * double a = Math.Truncate(gableCurve1.GeometryCurve.Length /2.00 * 100) / 100;
             * //double a = gableCurve1.GeometryCurve.Length / 2.00;
             *           //double n = wallCurv2.Curve.Length;
             * ////
             *
             * //double c = Math.Sqrt(a * a + b * b);
             * //double angleB = Math.Acos(c);
             *          //find double slope A use pythagorum theroum
             * // set lines a and b, find c
             *
             * //double b = 4.00; // height should be 4' from center
             * ////// <<<hey hey hey hey hey hey herrrreeeeeeeeee <<<<<<<<<<
             * /////LocationCurve wallCurv2 = (LocationCurve)walls[3].Location;
             *
             */

            double angleBRadians = Math.Atan(b / a);

            double angleB = Math.Tan(angleBRadians);

            TaskDialog.Show("Test Values",
                            "lenght a: " + a +
                            " length b: " + b +
                            " radians: " + angleBRadians +
                            " angle B: " + angleB);


            aRoof.set_DefinesSlope(gableCurve1, true);
            aRoof.set_SlopeAngle(gableCurve1, angleB);
            aRoof.set_DefinesSlope(gableCurve2, true);
            aRoof.set_SlopeAngle(gableCurve2, angleB);

            #region note text and abandoned code

            //foreach (ModelCurve modelCurve in mapping)
            //{
            //  aRoof.set_DefinesSlope(modelCurve, true);
            //  aRoof.set_SlopeAngle(modelCurve, 0.5);
            //}

            // Performed automatically by transaction commit.
            //rvtDoc.Regenerate();
            //rvtDoc.AutoJoinElements();
            #endregion
        }