Esempio n. 1
0
        /// <summary>
        /// Добавление окна.
        /// </summary>
        /// <param name="hostWall"></param>
        public void AddWindow(Wall hostWall)
        {
            // hard coding the window type we will use.
            // e.g., "M_Fixed: 0915 x 1830mm
            const string windowFamilyName        = "Фиксированные";  // "M_Fixed"
            const string windowTypeName          = "0915 x 1830 мм"; // "0915 x 1830mm"
            const string windowFamilyAndTypeName = windowFamilyName + ": " + windowTypeName;

            double sillHeight = ElementModification.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);
        }
Esempio n. 2
0
        /// <summary>
        /// Создать четыре стены.
        /// </summary>
        /// <returns></returns>
        public List <Wall> CreateWalls()
        {
            // hard coding the size of the house for simplicity
            double width = ElementModification.mmToFeet(10000.0);
            double depth = ElementModification.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 = (Level)ElementFiltering.FindElement(m_rvtDoc, typeof(Level), "Level 1", null);

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

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

            if (level2 == null)
            {
                TaskDialog.Show("Revit Intro Lab", "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>()
            {
                new XYZ(-dx, -dy, 0.0),
                new XYZ(dx, -dy, 0.0),
                new XYZ(dx, dy, 0.0),
                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 = Wall.Create(m_rvtDoc, baseCurve, level1.Id, isStructural);

                // 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.
            m_rvtDoc.Regenerate();
            m_rvtDoc.AutoJoinElements();

            return(walls);
        }