public void AddDoor(Wall hostWall)
        {
            const string doorFamilyName        = Constant.DoorFamilyName;
            const string doorTypeName          = Constant.DoorTypeName;
            const string doorFamilyAndTypeName = doorFamilyName + ": " + doorTypeName;

            // Get the door type to use.

            FamilySymbol doorType = (FamilySymbol)ElementFiltering.FindFamilyType(_doc, typeof(FamilySymbol), doorFamilyName, doorTypeName, BuiltInCategory.OST_Doors);

            if (doorType == null)
            {
                TaskDialog.Show("Add door", "Cannot find (" + doorFamilyAndTypeName + "). maybe you use a differnt template? Try with DefaultMetric.rte.");
            }

            if (!doorType.IsActive)
            {
                doorType.Activate();
            }

            // Get the start and end points of the wall.

            LocationCurve locCurve = (LocationCurve)hostWall.Location;

            XYZ pt1 = locCurve.Curve.GetEndPoint(0);
            XYZ pt2 = locCurve.Curve.GetEndPoint(1);

            XYZ pt = (pt1 + pt2) / 2.0;                                                                       // Calculate the mid point.

            ElementId idLevel1 = hostWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId(); //level wall

            Level level1 = (Level)_doc.GetElement(idLevel1);

            FamilyInstance aDoor = _doc.Create.NewFamilyInstance(pt, doorType, hostWall, level1, StructuralType.NonStructural);
        }
        public List <Wall> CreateWalls()
        {
            double width = Constant.MmToFeet(10000.0);
            double depth = Constant.MmToFeet(5000.0);

            Level level1 = (Level)ElementFiltering.FindElement(_doc, typeof(Level), "Level 1", null);

            if (level1 == null)
            {
                TaskDialog.Show("Create walls", "Cannot find (Level 1). Maybe you use a different template? Try with DefaultMetric.rte");
                return(null);
            }

            Level level2 = (Level)ElementFiltering.FindElement(_doc, typeof(Level), "Level 2", null);

            if (level2 == null)
            {
                TaskDialog.Show("Create walls", "Cannot find(Level 2). Maybe you use a different template? Try with DifaulMetric.rte.");
                return(null);
            }

            double dx = width / 2.0;
            double dy = depth / 2.0;

            List <XYZ> pts = new List <XYZ>(5);

            pts.Add(new XYZ(-dx, -dy, 0.0));
            pts.Add(new XYZ(dx, -dy, 0.0));
            pts.Add(new XYZ(dx, dy, 0.0));
            pts.Add(new XYZ(-dx, dy, 0.0));
            pts.Add(pts[0]);


            bool isStructural = false;              // Flag for structural wall or not.

            List <Wall> walls = new List <Wall>(4); // Save walls we create.

            for (int i = 0; i <= 3; i++)
            {
                Line baseCurve = Line.CreateBound(pts[i], pts[i + 1]);                 //создаем границу

                Wall aWall = Wall.Create(_doc, baseCurve, level1.Id, isStructural);    //create a wall

                aWall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(level2.Id); //set the top constraction to level 2

                walls.Add(aWall);
            }

            _doc.Regenerate();
            _doc.AutoJoinElements();

            return(walls);
        }
Ejemplo n.º 3
0
        public void AddWindow(Wall hostWall)
        {
            // hard coding the window type we will use.
            // e.g., "M_Fixed: 0915 x 1830mm

            const string windowFamilyName        = "Fixed";       // "M_Fixed"
            const string windowTypeName          = "16\" x 24\""; // "0915 x 1830mm"
            const string windowFamilyAndTypeName =
                windowFamilyName + ": " + windowTypeName;
            double sillHeight = Util.Constant.MmToFeet(915);

            // get the door type to use.

            FamilySymbol windowType =
                (FamilySymbol)ElementFiltering.FindFamilyType(
                    m_rvtDoc, typeof(FamilySymbol), windowFamilyName, windowTypeName,
                    BuiltInCategory.OST_Windows);

            if (windowType == null)
            {
                TaskDialog.Show("Revit Intro Lab", "Cannot find (" +
                                windowFamilyAndTypeName +
                                "). Try with DefaultMetric.rte.");
            }

            // get the start and end points of the wall.

            LocationCurve locCurve = (LocationCurve)hostWall.Location;
            XYZ           pt1      = locCurve.Curve.GetEndPoint(0);
            XYZ           pt2      = locCurve.Curve.GetEndPoint(1);
            // calculate the mid point.
            XYZ pt = (pt1 + pt2) / 2.0;

            // we want to set the reference as a bottom of the wall or level1.

            ElementId idLevel1 =
                hostWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).
                AsElementId();
            Level level1 = (Level)m_rvtDoc.GetElement(idLevel1);

            // finally create a window.

            FamilyInstance aWindow = m_rvtDoc.Create.NewFamilyInstance(
                pt, windowType, hostWall, level1, StructuralType.NonStructural);

            // set the sill height
            aWindow.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).
            Set(sillHeight);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add a window to the center of the wall given.
        /// cf. Developer Guide p137. NewFamilyInstance() for Doors and Window.
        /// Basically the same idea as a door except that we need to set sill hight.
        /// </summary>
        public void AddWindow(Wall hostWall)
        {
            // Hard coding the window type we will use.
            // E.g., "M_Fixed: 0915 x 1830mm

            const string windowFamilyName        = Util.Constant.WindowFamilyName;
            const string windowTypeName          = Util.Constant.WindowTypeName;
            const string windowFamilyAndTypeName = windowFamilyName + ": " + windowTypeName;
            double       sillHeight = Constant.MmToFeet(915);

            // Get the door type to use.

            FamilySymbol windowType = (FamilySymbol)ElementFiltering.FindFamilyType(_doc, typeof(FamilySymbol), windowFamilyName, windowTypeName, BuiltInCategory.OST_Windows);

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

            if (!windowType.IsActive)
            {
                windowType.Activate();
            }

            // Get the start and end points of the wall.

            LocationCurve locCurve = (LocationCurve)hostWall.Location;
            XYZ           pt1      = locCurve.Curve.GetEndPoint(0);
            XYZ           pt2      = locCurve.Curve.GetEndPoint(1);
            // Calculate the mid point.
            XYZ pt = (pt1 + pt2) / 2.0;

            // we want to set the reference as a bottom of the wall or level1.

            ElementId idLevel1 = hostWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId();
            //Level level1 = (Level)_doc.get_Element(idLevel1); // 2012
            Level level1 = (Level)_doc.GetElement(idLevel1); // since 2013

            // Finally create a window.

            FamilyInstance aWindow = _doc.Create.NewFamilyInstance(pt, windowType, hostWall, level1, StructuralType.NonStructural);

            aWindow.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).Set(sillHeight);
        }
Ejemplo n.º 5
0
        /// <summary>
        // Add a door to the center of the given wall.
        // cf. Developer Guide p137. NewFamilyInstance() for Doors and Window.
        /// </summary>
        public void AddDoor(Wall hostWall)
        {
            // Hard coding the door type we will use.
            // E.g., "M_Single-Flush: 0915 x 2134mm

            const string doorFamilyName        = Util.Constant.DoorFamilyName;
            const string doorTypeName          = Util.Constant.DoorTypeName;
            const string doorFamilyAndTypeName = doorFamilyName + ": " + doorTypeName;

            // Get the door type to use.

            FamilySymbol doorType = (FamilySymbol)ElementFiltering.FindFamilyType(_doc, typeof(FamilySymbol), doorFamilyName, doorTypeName, BuiltInCategory.OST_Doors);

            if (doorType == null)
            {
                TaskDialog.Show(
                    "Add door",
                    "Cannot find (" +
                    doorFamilyAndTypeName +
                    "). Maybe you use a different template? Try with DefaultMetric.rte.");
            }
            if (!doorType.IsActive)
            {
                doorType.Activate();
            }

            // Get the start and end points of the wall.

            LocationCurve locCurve = (LocationCurve)hostWall.Location;
            XYZ           pt1      = locCurve.Curve.GetEndPoint(0);
            XYZ           pt2      = locCurve.Curve.GetEndPoint(1);
            // Calculate the mid point.
            XYZ pt = (pt1 + pt2) / 2.0;

            // we want to set the reference as a bottom of the wall or level1.

            ElementId idLevel1 =
                hostWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId();

            //Level level1 = (Level)_doc.get_Element(idLevel1); // 2012
            Level level1 = (Level)_doc.GetElement(idLevel1); // since 2013

            // Finally, create a door.

            FamilyInstance aDoor =
                _doc.Create.NewFamilyInstance(
                    pt, doorType, hostWall, level1, StructuralType.NonStructural);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// A sampler function to demonstrate how to modify an element through its properties.
        /// Using a door as an example here.
        /// </summary>
        public void ModifyElementPropertiesDoor(Element e)
        {
            // Constant to this function.
            // This is for a door. e.g., "M_Single-Flush: 0762 x 2032mm"
            // You can modify this to fit your need.

            const string doorFamilyName        = Util.Constant.DoorFamilyName;
            const string doorTypeName          = Util.Constant.DoorTypeName2;
            const string doorFamilyAndTypeName = doorFamilyName + ": " + doorTypeName;

            // For simplicity, we assume we can only modify a door
            if (!(e is FamilyInstance))
            {
                TaskDialog.Show(
                    "Modify element properties - door",
                    "Sorry, I only know how to modify a door. Please select a door.");
                return;
            }
            FamilyInstance aDoor = (FamilyInstance)e;

            string msg = "Door changed:\n\n";

            // (1) change its family type to a different one.

            Element newDoorType = ElementFiltering.FindFamilyType(_doc, typeof(FamilySymbol), doorFamilyName, doorTypeName, BuiltInCategory.OST_Doors);

            if (newDoorType != null)
            {
                aDoor.Symbol = (FamilySymbol)newDoorType;
                msg         += "Door type to: " + doorFamilyAndTypeName + "\r\n";
                //TaskDialog.Show("Modify element properties - door", msg);
            }

            // (2) change its parameters.
            // leave this as your exercise.


            // message to the user.
            TaskDialog.Show("Modify element properties - door", msg);
        }
        /// <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.

            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();
        }
        /// <summary>
        /// Create walls with a rectangular profile from two coner points.
        /// </summary>
        public static List <Wall> CreateWalls(Document rvtDoc, XYZ pt1, XYZ pt2)
        {
            // Set the lower-left (x1, y1) and upper-right (x2, y2) corners of a house.
            double x1 = pt1.X;
            double x2 = pt2.X;

            if (pt1.X > pt2.X)
            {
                x1 = pt2.X;
                x2 = pt1.X;
            }

            double y1 = pt1.Y;
            double y2 = pt2.Y;

            if (pt1.Y > pt2.X)
            {
                y1 = pt2.Y;
                y2 = pt1.Y;
            }

            // Set four corner of walls from two croner point.
            // 5th point is for combenience to loop through.
            List <XYZ> pts = new List <XYZ>(5);

            pts.Add(new XYZ(x1, y1, pt1.Z));
            pts.Add(new XYZ(x2, y1, pt1.Z));
            pts.Add(new XYZ(x2, y2, pt1.Z));
            pts.Add(new XYZ(x1, y2, pt1.Z));
            pts.Add(pts[0]);

            // Get the levels we want to work on.
            // Note: hard coding for simplicity. Modify here you use a different template.
            Level level1 = ElementFiltering.FindElement(rvtDoc, typeof(Level), "Level 1", null) as Level;

            if (level1 == null)
            {
                TaskDialog.Show(
                    "Create walls", "Cannot find (Level 1). Maybe you use a different template? Try with DefaultMetric.rte."
                    );
                return(null);
            }

            Level level2 = ElementFiltering.FindElement(rvtDoc, typeof(Level), "Level 2", null) as Level;

            if (level2 == null)
            {
                TaskDialog.Show(
                    "Create walls", "Cannot find (Level 2). Maybe you use a different template? Try with DefaultMetric.rte."
                    );
                return(null);
            }

            // Flag for structural wall or not.
            bool isStructural = false;

            // Save walls we create.
            List <Wall> walls = new List <Wall>(4);

            // Loop through list of points and define four walls.
            for (int i = 0; i <= 3; i++)
            {
                // define a base curve from two points.
                Line baseCurve = Line.CreateBound(pts[i], pts[i + 1]);
                // create a wall using the one of overloaded methods.
                //Wall aWall = rvtDoc.Create.NewWall(baseCurve, level1, isStructural); // 2012
                Wall aWall = Wall.Create(rvtDoc, baseCurve, level1.Id, isStructural); // since 2013
                // set the Top Constraint to Level 2
                aWall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(level2.Id);
                // save the wall.
                walls.Add(aWall);
            }
            // This is important. we need these lines to have shrinkwrap working.
            rvtDoc.Regenerate();
            rvtDoc.AutoJoinElements();

            return(walls);
        }
        /// <summary>
        /// There are five override methods for creating walls.
        /// We assume you are using metric template, where you have
        /// "Level 1" and "Level 2"
        /// cf. Developer Guide page 117
        /// </summary>
        public List <Wall> CreateWalls_v1()
        {
            // Hard coding the size of the house for simplicity
            double width = Constant.MmToFeet(10000.0);
            double depth = Constant.MmToFeet(5000.0);

            // Get the levels we want to work on.
            // Note: hard coding for simplicity. Modify here you use a different template.
            Level level1 = ElementFiltering.FindElement(_doc, typeof(Level), "Level 1", null) as Level;

            if (level1 == null)
            {
                TaskDialog.Show("Create walls",
                                "Cannot find (Level 1). Maybe you use a different template? Try with DefaultMetric.rte.");
                return(null);
            }

            Level level2 = ElementFiltering.FindElement(_doc, typeof(Level), "Level 2", null) as Level;

            if (level2 == null)
            {
                TaskDialog.Show("Create walls",
                                "Cannot find (Level 2). Maybe you use a different template? Try with DefaultMetric.rte.");
                return(null);
            }

            // Set four corner of walls.
            // 5th point is for combenience to loop through.
            double dx = width / 2.0;
            double dy = depth / 2.0;

            List <XYZ> pts = new List <XYZ>(5);

            pts.Add(new XYZ(-dx, -dy, 0.0));
            pts.Add(new XYZ(dx, -dy, 0.0));
            pts.Add(new XYZ(dx, dy, 0.0));
            pts.Add(new XYZ(-dx, dy, 0.0));
            pts.Add(pts[0]);

            // Flag for structural wall or not.
            bool isStructural = false;

            // Save walls we create.
            List <Wall> walls = new List <Wall>(4);

            // Loop through list of points and define four walls.
            for (int i = 0; i <= 3; i++)
            {
                // Define a base curve from two points.
                Line baseCurve = Line.CreateBound(pts[i], pts[i + 1]);
                // Create a wall using the one of overloaded methods.

                //Wall aWall = _doc.Create.NewWall(baseCurve, level1, isStructural); // 2012
                Wall aWall = Wall.Create(_doc, baseCurve, level1.Id, isStructural); // since 2013

                // Set the Top Constraint to Level 2
                aWall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(level2.Id);
                // Save the wall.
                walls.Add(aWall);
            }

            // This is important. we need these lines to have shrinkwrap working.
            _doc.Regenerate();
            _doc.AutoJoinElements();

            return(walls);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// A sampler function to demonstrate how to modify an element through its properties.
        /// Using a wall as an example here.
        /// </summary>
        public void ModifyElementPropertiesWall(Element e)
        {
            // Constant to this function.
            // This is for wall. e.g., "Basic Wall: Exterior - Brick on CMU"
            // You can modify this to fit your need.

            const string wallFamilyName        = Util.Constant.WallFamilyName;
            const string wallTypeName          = "Exterior - Brick on CMU";
            const string wallFamilyAndTypeName = wallFamilyName + ": " + wallTypeName;

            // For simplicity, we assume we can only modify a wall
            if (!(e is Wall))
            {
                TaskDialog.Show(
                    "Modify element properties - wall",
                    "Sorry, I only know how to modify a wall. Please select a wall.");
                return;
            }
            Wall aWall = (Wall)e;

            string msg = "Wall changed:\r\n\r\n"; // Keep the message to the user.

            // (1) change its family type to a different one.
            // To Do: change this to enhance import symbol later.

            Element newWallType = ElementFiltering.FindFamilyType(_doc, typeof(WallType), wallFamilyName, wallTypeName, null);

            if (newWallType != null)
            {
                aWall.WallType = (WallType)newWallType;
                msg           += "Wall type to: " + wallFamilyAndTypeName + "\r\n";
            }
            //TaskDialog.Show(
            //  "Modify element properties - wall",
            //  msg )

            // (2) change its parameters.
            // As a way of exercise, let's constrain top of the wall to the level1 and set an offset.

            // Find the level 1 using the helper function we defined in the lab3.
            Level level1 = (Level)ElementFiltering.FindElement(_doc, typeof(Level), "Level 1", null);

            if (level1 != null)
            {
                // Top Constraint
                aWall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(level1.Id);
                msg += "Top Constraint to: Level 1\r\n";
            }

            // Hard coding for simplicity here.
            double topOffset = Constant.MmToFeet(5000.0);

            // Top Offset Double
            aWall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).Set(topOffset);
            // Structural Usage = Bearing(1)
            //aWall.get_Parameter(BuiltInParameter.WALL_STRUCTURAL_USAGE_PARAM).Set(1); // This is read only
            // Comments - String
            aWall.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set("Modified by API");

            msg += "Top Offset to: 5000.0\r\n";
            msg += "Structural Usage to: Bearing\r\n";
            msg += "Comments added: Modified by API\r\n";
            //TaskDialog.Show("Modify element properties - wall", msg );

            // (3) Optional: change its location, using location curve
            // LocationCurve also has move and rotation methods.
            // Note: constaints affect the result.
            // Effect will be more visible with disjoined wall.
            // To test this, you may want to draw a single standing wall,
            // and run this command.

            LocationCurve wallLocation = (LocationCurve)aWall.Location;

            XYZ pt1 = wallLocation.Curve.GetEndPoint(0);
            XYZ pt2 = wallLocation.Curve.GetEndPoint(1);

            // Hard coding the displacement value for simility here.
            double dt     = Constant.MmToFeet(1000.0);
            XYZ    newPt1 = new XYZ(pt1.X - dt, pt1.Y - dt, pt1.Z);
            XYZ    newPt2 = new XYZ(pt2.X - dt, pt2.Y - dt, pt2.Z);

            // Create a new line bound.
            Line newWallLine = Line.CreateBound(newPt1, newPt2);

            // Finally change the curve.
            wallLocation.Curve = newWallLine;

            msg += "Location: start point moved -1000.0 in X-direction\r\n";

            // Message to the user.

            TaskDialog.Show("Modify element properties - wall", msg);
        }
        public void AddRoof(List <Wall> walls)
        {
            // Hard coding the roof type we will use.
            // E.g., "Basic Roof: Generic - 400mm"

            const string roofFamilyName        = "Базовая крыша";
            const string roofTypeName          = Constant.RoofTypeName;
            const string roofFamilyAndTypeName = roofFamilyName + ": " + roofTypeName;

            // Find the roof type

            RoofType roofType = (RoofType)ElementFiltering.FindFamilyType(_doc, typeof(RoofType), roofFamilyName, roofTypeName, null);

            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.


            double wallThickness = walls[0].Width;

            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.GetElement(idLevel2); // since 2013

            // Footprint to model curve mapping

            ModelCurveArray mapping = new ModelCurveArray();

            // Create a roof.

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

            foreach (ModelCurve modelCurve in mapping)
            {
                aRoof.set_DefinesSlope(modelCurve, true);
                aRoof.set_SlopeAngle(modelCurve, 0.5);
            }
        }
Ejemplo n.º 12
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
        }
Ejemplo n.º 13
0
        public void AddRoof(Document rvtDoc, List <Wall> walls)
        {
            // Hardcoding the roof type we will use.
            // e.g., "Basic Roof: Generic - 400mm"

            const string roofFamilyName        = "Basic Roof";
            const string roofTypeName          = "Generic - 9\"";
            const string roofFamilyAndTypeName = roofFamilyName + ": " + roofTypeName;

            // Find the roof type

            RoofType roofType = (RoofType)ElementFiltering.FindFamilyType(
                rvtDoc,
                typeof(RoofType),
                roofFamilyName,
                roofTypeName,
                null);

            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 excercise.
             * DIM wallThickness as Double
             */
            double wallThickness = walls[0].WallType.GetCompoundStructure().GetLayers()[0].Width;

            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 wals
            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);
            }

            /////////////////////////////////////////////////
            ///new mapping
            /////////////////////////////////////////////////
            Curve      getCurveOne     = footPrint.get_Item(1);
            Curve      getCurveTwo     = footPrint.get_Item(3);
            CurveArray gabledFootprint = new CurveArray();

            gabledFootprint.Append(getCurveOne);
            gabledFootprint.Append(getCurveTwo);

            // get the lvl2 from wall

            ElementId idlvl2 = walls[0].get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId();
            Level     lvl2   = rvtDoc.GetElement(idlvl2) as Level;

            ModelCurveArray mapping = new ModelCurveArray();                                               // footprint to model curve mapping
            FootPrintRoof   aRoof   = rvtDoc.Create.NewFootPrintRoof(footPrint, lvl2, roofType, out mapping);


            //double offsetValue = 10;


            foreach /*set the slope */ (ModelCurve modelCurve in mapping)
            {
                aRoof.set_DefinesSlope(modelCurve, true);
                aRoof.set_SlopeAngle(modelCurve, 0.5);
                //aRoof.set_Offset(modelCurve, offsetValue);
            }

            /* performed automatically by transaction commit.
             * rvtDoc.Regenerate();
             * rvtDoc.AutoJoinElement();
             */
        }