NewExtrusion Method


Add a new Extrusion instance into the Autodesk Revit family document.

Namespace: Autodesk.Revit.Creation
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)

Syntax

C#
public Extrusion NewExtrusion(
	bool isSolid,
	CurveArrArray profile,
	SketchPlane sketchPlane,
	double end
)
Visual Basic
Public Function NewExtrusion ( _
	isSolid As Boolean, _
	profile As CurveArrArray, _
	sketchPlane As SketchPlane, _
	end As Double _
) As Extrusion
Visual C++
public:
Extrusion^ NewExtrusion(
	bool isSolid, 
	CurveArrArray^ profile, 
	SketchPlane^ sketchPlane, 
	double end
)

Parameters

isSolid
Type: System Boolean
Indicates if the Extrusion is Solid or Void.
profile
Type: Autodesk.Revit.DB CurveArrArray
The profile of the newly created Extrusion. This may contain more than one curve loop. Each loop must be a fully closed curve loop and the loops may not intersect. All input curves must lie in the same plane. The loop can be a unbound circle or ellipse, but its geometry will be split in two in order to satisfy requirements for sketches used in extrusions.
sketchPlane
Type: Autodesk.Revit.DB SketchPlane
The sketch plane for the extrusion. The direction of extrusion is determined by the normal for the sketch plane. To extrude in the other direction set the end value to negative.
end
Type: System Double
The length of the extrusion.

Return Value

If creation was successful the new Extrusion is returned, otherwise an exception with failure information will be thrown.

Remarks

This method creates an extrusion in a family document. The extrusion will be extended perpendicular to the sketch plane of the extrusion profile.

Examples

Copy C#
private Extrusion CreateExtrusion(Autodesk.Revit.DB.Document document, SketchPlane sketchPlane)
{
    Extrusion rectExtrusion = null;

    // make sure we have a family document
    if (true == document.IsFamilyDocument)
    {
        // define the profile for the extrusion
        CurveArrArray curveArrArray = new CurveArrArray();
        CurveArray curveArray1 = new CurveArray();
        CurveArray curveArray2 = new CurveArray();
        CurveArray curveArray3 = new CurveArray();

        // create a rectangular profile
        XYZ p0 = XYZ.Zero;
        XYZ p1 = new XYZ(10, 0, 0);
        XYZ p2 = new XYZ(10, 10, 0);
        XYZ p3 = new XYZ(0, 10, 0);
        Line line1 = Line.CreateBound(p0, p1);
        Line line2 = Line.CreateBound(p1, p2);
        Line line3 = Line.CreateBound(p2, p3);
        Line line4 = Line.CreateBound(p3, p0);
        curveArray1.Append(line1);
        curveArray1.Append(line2);
        curveArray1.Append(line3);
        curveArray1.Append(line4);

        curveArrArray.Append(curveArray1);

        // create solid rectangular extrusion
        rectExtrusion = document.FamilyCreate.NewExtrusion(true, curveArrArray, sketchPlane, 10);

        if (null != rectExtrusion)
        {
            // move extrusion to proper place
            XYZ transPoint1 = new XYZ(-16, 0, 0);
            ElementTransformUtils.MoveElement(document, rectExtrusion.Id, transPoint1);
        }
        else
        {
            throw new Exception("Create new Extrusion failed.");
        }
    }
    else
    {
        throw new Exception("Please open a Family document before invoking this command.");
    }

    return rectExtrusion;
}
Copy VB.NET
Private Function CreateExtrusion(document As Autodesk.Revit.DB.Document, sketchPlane As SketchPlane) As Extrusion
    Dim rectExtrusion As Extrusion = Nothing

    ' make sure we have a family document
    If True = document.IsFamilyDocument Then
        ' define the profile for the extrusion
        Dim curveArrArray As New CurveArrArray()
        Dim curveArray1 As New CurveArray()
        Dim curveArray2 As New CurveArray()
        Dim curveArray3 As New CurveArray()

        ' create a rectangular profile
        Dim p0 As XYZ = XYZ.Zero
        Dim p1 As New XYZ(10, 0, 0)
        Dim p2 As New XYZ(10, 10, 0)
        Dim p3 As New XYZ(0, 10, 0)
        Dim line1 As Line = Line.CreateBound(p0, p1)
        Dim line2 As Line = Line.CreateBound(p1, p2)
        Dim line3 As Line = Line.CreateBound(p2, p3)
        Dim line4 As Line = Line.CreateBound(p3, p0)
        curveArray1.Append(line1)
        curveArray1.Append(line2)
        curveArray1.Append(line3)
        curveArray1.Append(line4)

        curveArrArray.Append(curveArray1)

        ' create solid rectangular extrusion
        rectExtrusion = document.FamilyCreate.NewExtrusion(True, curveArrArray, sketchPlane, 10)

        If rectExtrusion IsNot Nothing Then
            ' move extrusion to proper place
            Dim transPoint1 As New XYZ(-16, 0, 0)
            ElementTransformUtils.MoveElement(document, rectExtrusion.Id, transPoint1)
        Else
            Throw New Exception("Create new Extrusion failed.")
        End If
    Else
        Throw New Exception("Please open a Family document before invoking this command.")
    End If

    Return rectExtrusion
End Function

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentException Thrown when the input argument-profile-is a null reference ( Nothing in Visual Basic) or empty array.
Autodesk.Revit.Exceptions ArgumentNullException Thrown when the input argument-sketchPlane-is a null reference ( Nothing in Visual Basic) .
Autodesk.Revit.Exceptions ArgumentException Thrown when the input argument-sketchPlane-is an invalid sketch plane.
Autodesk.Revit.Exceptions InvalidOperationException Thrown when the creation failed.

See Also