Solid analysis

Solid analysis

Intersection between solid and curve

The method Solid.IntersectWithCurve() calculates the intersection between a closed volume solid and a curve. The SolidCurveIntersectionOptions class can specify whether the results from the IntersectWithCurve() method will include curve segments inside the solid volume or outside. The curve segments inside the solid will include curve segments coincident with the face(s) of the solid. Both the curve segments and the parameters of the segments are available in the results.

The following example uses the IntersectWithCurve() method to calculate the length of rebar that lies within a column.

Code Region: Finding intersection between solid and curve

void FindColumnRebarIntersections(Document document, FamilyInstance column)
{
    // Find rebar hosted by this column
    RebarHostData rebarHostData = RebarHostData.GetRebarHostData(column);
    if (null != rebarHostData)
    {
        IList<Rebar> rebars = rebarHostData.GetRebarsInHost();
        if (rebars.Count > 0)
        {
            Options geomOptions = new Options();
            geomOptions.ComputeReferences = true;
            geomOptions.DetailLevel = ViewDetailLevel.Fine;
            GeometryElement geomElement = column.get_Geometry(geomOptions);
            foreach (GeometryObject geomObj in geomElement)
            {
                GeometryInstance geomInst = geomObj as GeometryInstance;
                if (null != geomInst)
                {
                    GeometryElement columnGeometry = geomInst.GetInstanceGeometry();
                    foreach (GeometryObject obj in columnGeometry)
                    {
                        Solid solid = obj as Solid;
                        if (null != solid)
                        {
                            SolidCurveIntersectionOptions options = new SolidCurveIntersectionOptions();
                            foreach (Rebar rebar in rebars)
                            {
                                // Get the centerlines for the rebar to find their intersection with the collumn
                                IList<Curve> curves = rebar.GetCenterlineCurves(false, false, false);
                                foreach (Curve curve in curves)
                                {
                                    SolidCurveIntersection intersection = solid.IntersectWithCurve(curve, options);
                                    for (int n = 0; n < intersection.SegmentCount; n++)
                                    {
                                        // calculate length of rebar that is inside the column
                                        Curve curveInside = intersection.GetCurveSegment(n);
                                        double rebarLengthinColumn = curveInside.Length;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}