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.
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.Value;
//get the information whether the opening has a rect boundary
//If the opening has a rect boundary, get the geom info 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
XYZArray boundaryRect = opening.BoundaryRect;
//get the coordinate value of the min coordinate point
XYZ point = opening.BoundaryRect.get_Item(0);
message += "\nMin coordinate point:(" + point.X + ", "
+ point.Y + ", " + point.Z + ")";
//get the coordinate value of the Max coordinate point
point = opening.BoundaryRect.get_Item(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.Geometry.Curve curve = opening.BoundaryCurves.get_Item(i);
// Get curve start and end points
message += "\nCurve start point: " + XYZToString(curve.get_EndPoint(0));
message += "; Curve end point: " + XYZToString(curve.get_EndPoint(1));
}
}
MessageBox.Show(message, "Revit");
}
// 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:
- 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.
NoteUsing 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.