IntersectWithCurve Method


Calculates and returns the intersection between a curve and this solid.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 17.0.0.0 (17.0.1090.0)
Since: 2013

Syntax

C#
public SolidCurveIntersection IntersectWithCurve(
	Curve curve,
	SolidCurveIntersectionOptions options
)
Visual Basic
Public Function IntersectWithCurve ( _
	curve As Curve, _
	options As SolidCurveIntersectionOptions _
) As SolidCurveIntersection
Visual C++
public:
SolidCurveIntersection^ IntersectWithCurve(
	Curve^ curve, 
	SolidCurveIntersectionOptions^ options
)

Parameters

curve
Type: Autodesk.Revit.DB Curve
The curve.
options
Type: Autodesk.Revit.DB SolidCurveIntersectionOptions
The options. If NULL, the default options will be used.

Return Value

The intersection results.

Examples

Copy C#
private void FindColumnRebarIntersections(Document document, FamilyInstance column)
{
    // We will be computing the total length of the rebar inside the column
    double totalRebarLengthInColumn = 0;

    // Find rebar hosted by this column
    RebarHostData rebarHostData = RebarHostData.GetRebarHostData(column);
    if (rebarHostData == null)
    {
        return;
    }

    IList<Rebar> rebars = rebarHostData.GetRebarsInHost();
    if (rebars.Count == 0)
    {
        return;
    }

    // Retrieve geometry of the column
    Options geomOptions = new Options();
    geomOptions.ComputeReferences = true;
    geomOptions.DetailLevel = ViewDetailLevel.Fine;
    GeometryElement elemGeometry = column.get_Geometry(geomOptions);

    // Examine all geometry primitives of the column
    foreach (GeometryObject elemPrimitive in elemGeometry)
    {

        // Skip objects that are not geometry instances
        GeometryInstance gInstance = elemPrimitive as GeometryInstance;
        if (gInstance == null)
        {
            continue;
        }

        // Retrieve geometry of each found geometry instance
        GeometryElement instGeometry = gInstance.GetInstanceGeometry();
        foreach (GeometryObject instPrimitive in instGeometry)
        {

            // Skip non-solid sobject
            Solid solid = instPrimitive as Solid;
            if (solid == null)
            {
                continue;
            }

            SolidCurveIntersectionOptions intersectOptions = new SolidCurveIntersectionOptions();
            foreach (Rebar rebar in rebars)
            {
                // Get the centerlines for the rebar to find their intersection with the column
                bool selfIntersection = false;
                bool suppresHooks = false;
                bool suppresBends = false;
                IList<Curve> curves = rebar.GetCenterlineCurves(selfIntersection, suppresHooks, suppresBends, MultiplanarOption.IncludeOnlyPlanarCurves, 0);

                // Examine every segment of every curve of the centerline
                foreach (Curve curve in curves)
                {
                    SolidCurveIntersection intersection = solid.IntersectWithCurve(curve, intersectOptions);
                    for (int segment = 0; segment <= intersection.SegmentCount - 1; segment++)
                    {
                        // Calculate length of the rebar that is inside the column
                        Curve curveInside = intersection.GetCurveSegment(segment);
                        double rebarLengthInColumn = curveInside.Length;
                        totalRebarLengthInColumn = totalRebarLengthInColumn + rebarLengthInColumn;
                    }
                }

            }
        }
    }

}
Copy VB.NET
Private Sub FindColumnRebarIntersections(document As Document, column As FamilyInstance)
    ' We will be computing the total length of the rebar inside the column
    Dim totalRebarLengthInColumn As Double = 0

    ' Find rebar hosted by this column
    Dim rebarHostData__1 As RebarHostData = RebarHostData.GetRebarHostData(column)
    If rebarHostData__1 Is Nothing Then
        Return
    End If

    Dim rebars As IList(Of Rebar) = rebarHostData__1.GetRebarsInHost()
    If rebars.Count = 0 Then
        Return
    End If

    ' Retrieve geometry of the column
    Dim geomOptions As New Options()
    geomOptions.ComputeReferences = True
    geomOptions.DetailLevel = ViewDetailLevel.Fine
    Dim elemGeometry As GeometryElement = column.Geometry(geomOptions)

    ' Examine all geometry primitives of the column
    For Each elemPrimitive As GeometryObject In elemGeometry

        ' Skip objects that are not geometry instances
        Dim gInstance As GeometryInstance = TryCast(elemPrimitive, GeometryInstance)
        If gInstance Is Nothing Then
            Continue For
        End If

        ' Retrieve geometry of each found geometry instance
        Dim instGeometry As GeometryElement = gInstance.GetInstanceGeometry()
        For Each instPrimitive As GeometryObject In instGeometry

            ' Skip non-solid sobject
            Dim solid As Solid = TryCast(instPrimitive, Solid)
            If solid Is Nothing Then
                Continue For
            End If

            Dim intersectOptions As New SolidCurveIntersectionOptions()
            For Each rebar As Rebar In rebars
                ' Get the centerlines for the rebar to find their intersection with the column
                Dim selfIntersection As Boolean = False
                Dim suppresHooks As Boolean = False
                Dim suppresBends As Boolean = False
                Dim curves As IList(Of Curve) = rebar.GetCenterlineCurves(selfIntersection, suppresHooks, suppresBends, MultiplanarOption.IncludeOnlyPlanarCurves, 0)

                ' Examine every segment of every curve of the centerline
                For Each curve As Curve In curves
                    Dim intersection As SolidCurveIntersection = solid.IntersectWithCurve(curve, intersectOptions)
                    For segment As Integer = 0 To intersection.SegmentCount - 1
                        ' Calculate length of the rebar that is inside the column
                        Dim curveInside As Curve = intersection.GetCurveSegment(segment)
                        Dim rebarLengthInColumn As Double = curveInside.Length
                        totalRebarLengthInColumn = totalRebarLengthInColumn + rebarLengthInColumn
                    Next

                Next
            Next
        Next
    Next

End Sub

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentException The input curve is not bound. -or- The input solid is not a closed volume.
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was NULL

See Also

ArchiLabs Desktop

Put AI to work inside Revit.

Give Desktop your instructions and project files to build Revit families, update model elements, and create views and schedules. Works directly in Revit and AutoCAD.

Explore Desktop →