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);
        }
        /// <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);
        }
예제 #4
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);
        }