ソリッド解析

ソリッドと曲線の交点

メソッド Solid.IntersectWithCurve()は、閉じたソリッド ボリュームと曲線の交点を計算します。SolidCurveIntersectionOptions クラスは、IntersectWithCurve()メソッドからの結果にソリッド ボリュームの内側または外側の曲線セグメントが含まれるかどうかを指定できます。ソリッドの内側の曲線セグメントには、ソリッドの面と一致する曲線セグメントが含まれます。曲線セグメントとセグメントのパラメータの両方が結果で使用できます。

次の例では、IntersectWithCurve()メソッドを使用して、列にある鉄筋の長さを計算します。

コード領域: ソリッドと曲線の交点を検出

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;
                    }
                }

            }
        }
    }

}