Opening

Opening

In the Revit Platform API, the Opening object is derived from the Element object and contains all of the Element object properties and methods. To retrieve all Openings in a project, use Document.ElementIterator to find the Elements.Opening objects.

General Properties

This section explains how to use the Opening properties.

  • IsRectBoundary - Identifies whether the opening has a rectangular boundary.
    • If true, it means the Opening has a rectangular boundary and you can get an IList<XYZ> collection from the Opening BoundaryRect property. Otherwise, the property returns null.
    • If false, you can get a CurveArray object from the BoundaryCurves property.
  • BoundaryCurves - If the opening boundary is not a rectangle, this property retrieves geometry information; otherwise it returns null. The property returns a CurveArray object containing the curves that represent the Opening object boundary.

    For more details about Curve, refer to Geometry.

  • BoundaryRect - If the opening boundary is a rectangle, you can get the geometry information using this property; otherwise it returns null.
    • The property returns an IList<XYZ> collection containing the XYZ coordinates.
    • The IList<XYZ> collection usually contains the rectangle boundary minimum (lower left) and the maximum (upper right) coordinates.
  • Host - The host property retrieves the Opening host element. The host element is the element cut by the Opening object.
    Note: Note If the Opening object's category is Shaft Openings, the Opening host is null.

The following example illustrates how to retrieve the existing Opening properties.

Code Region 11-6: Retrieving existing opening properties

private void Getinfo_Opening(Opening opening)
{
    string message = "Opening:";

    //get the host element of this opening
    message += "\nThe id of the opening's host element is : " + opening.Host.Id.IntegerValue;

    //get the information whether the opening has a rect boundary
    //If the opening has a rect boundary, we can get the geometry information from BoundaryRect property.
    //Otherwise we should get the geometry information from BoundaryCurves property
    if (opening.IsRectBoundary)
    {
        message += "\nThe opening has a rectangular boundary.";
        //array contains two XYZ objects: the max and min coords of boundary
        IList<XYZ> boundaryRect = opening.BoundaryRect;

        //get the coordinate value of the min coordinate point
        XYZ point = opening.BoundaryRect[0];
        message += "\nMin coordinate point:(" + point.X + ", "
                                + point.Y + ", " + point.Z + ")";

        //get the coordinate value of the Max coordinate point
        point = opening.BoundaryRect[1];
        message += "\nMax coordinate point: (" + point.X + ", "
                                + point.Y + ", " + point.Z + ")";
    }
    else
    {
        message += "\nThe opening doesn't have a rectangular boundary.";
        // Get curve number
        int curves = opening.BoundaryCurves.Size;
        message += "\nNumber of curves is : " + curves;
        for (int i = 0; i < curves; i++)
        {
            Autodesk.Revit.DB.Curve curve = opening.BoundaryCurves.get_Item(i);
            // Get curve start point
            message += "\nCurve start point: " + XYZToString(curve.GetEndPoint(0));
            // Get curve end point
            message += "; Curve end point: " + XYZToString(curve.GetEndPoint(1));
        }
    }
    TaskDialog.Show("Revit",message);
}

// output the point's three coordinates
string XYZToString(XYZ point)
{
    return "(" + point.X + ", " + point.Y + ", " + point.Z + ")";
}

Create Opening

In the Revit Platform API, use the Document.NewOpening() method to create an opening in your project. There are four method overloads you can use to create openings in different host elements:

Code Region 11-7: NewOpening()

//Create a new Opening in a beam, brace and column. 
public Opening NewOpening(Element famInstElement, CurveArray profile, eRefFace iFace); 
//Create a new Opening in a roof, floor and ceiling. 
public Opening NewOpening(Element hostElement, CurveArray profile, bool bPerpendicularFace);
//Create a new Opening Element. 
public Opening NewOpening(Level bottomLevel, Level topLevel, CurveArray  profile);
//Create an opening in a straight wall or arc wall. 
public Opening NewOpening(Wall, XYZ pntStart, XYZ pntEnd);
  • Create an Opening in a Beam, Brace, or Column - Use to create an opening in a family instance. The iFace parameter indicates the face on which the opening is placed.
  • Create a Roof, Floor, or Ceiling Opening - Use to create an opening in a roof, floor, or ceiling.
  • The bPerpendicularFace parameter indicates whether the opening is perpendicular to the face or vertical.
  • If the parameter is true, the opening is perpendicular to the host element face. See the following picture:

    Figure 39: Opening cut perpendicular to the host element face

    Figure 40: Opening cut vertically to the host element

  • Create a New Opening Element - Use to create a shaft opening in your project. However, make sure the topLevel is higher than the bottomLevel; otherwise an exception is thrown.
  • Create an Opening in a Straight Wall or Arc Wall - Use to create a rectangle opening in a wall. The coordinates of pntStart and pntEnd should be corner coordinates that can shape a rectangle. For example, the lower left corner and upper right corner of a rectangle. Otherwise an exception is thrown.
Note: Using the Opening command you can only create a rectangle shaped wall opening. To create some holes in a wall, edit the wall profile instead of the Opening command.