ソリッドを作成する(.NET)

ソリッド オブジェクト(Solid3d オブジェクト)は、オブジェクト全体を表します。ソリッドは、3 種類のモデリングの中で最も情報量が多く明確に定義されたモデルです。また、複雑な形状の場合も、ワイヤフレームやメッシュより作成および編集が簡単です。

直方体、球、くさびなどの基本的なソリッド形状は、Solid3d オブジェクトのメンバー メソッドとプロパティを使用して作成します。また、パスに沿ってリージョン オブジェクトを押し出したり、軸を中心にして 2D オブジェクトを回転させたりすることもできます。

メッシュと同様に、ソリッドは、隠面処理、シェーディング、レンダリングを行わなければ、ワイヤフレームとして表示されます。さらに、ソリッドを解析して物理的特性(量、慣性モーメント、重心など)を取得することができます。次の MassProperties プロパティを使用して、Solid3d オブジェクトと関連付けられた Solid3dMassProperties オブジェクトをクエリーできます。Solid3dMassProperties オブジェクトに含まれるプロパティ(MomentOfInertia、PrincipalAxes、PrincipalMoments、ProductOfInertia、RadiiOfGyration、Volume)を使用して、ソリッドを分析できます。

ソリッドの表示には、現在の表示スタイルおよび 3D モデリング関連のシステム変数が反映されます。ソリッドの表示に影響を与えるシステム変数としては、ISOLINES や FACETRES などがあります。ISOLINES は、ワイヤフレームの曲線部分を表現するために使用される面分割線の数をコントロールします。FACETRES は、シェーディングしたオブジェクトや、隠線処理したオブジェクトの滑らかさを調整します。

くさび型ソリッドを作成する

次の例では、くさび型ソリッドを作成します。くさびの 3 次元的な特質を表示できるように、アクティブ ビューポートのビュー方向を更新します。

C# の例

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
 
[CommandMethod("CreateWedge")]
public static void CreateWedge()
{
    // Get the current document and database, and start a transaction
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
    Database acCurDb = acDoc.Database;

    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
    {
        // Open the Block table record for read
        BlockTable acBlkTbl;
        acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                     OpenMode.ForRead) as BlockTable;

        // Open the Block table record Model space for write
        BlockTableRecord acBlkTblRec;
        acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                        OpenMode.ForWrite) as BlockTableRecord;

        // Create a 3D solid wedge
        using (Solid3d acSol3D = new Solid3d())
        {
            acSol3D.CreateWedge(10, 15, 20);

            // Position the center of the 3D solid at (5,5,0) 
            acSol3D.TransformBy(Matrix3d.Displacement(new Point3d(5, 5, 0) -
                                                      Point3d.Origin));

            // Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(acSol3D);
            acTrans.AddNewlyCreatedDBObject(acSol3D, true);
        }

        // Open the active viewport
        ViewportTableRecord acVportTblRec;
        acVportTblRec = acTrans.GetObject(acDoc.Editor.ActiveViewportId,
                                          OpenMode.ForWrite) as ViewportTableRecord;

        // Rotate the view direction of the current viewport
        acVportTblRec.ViewDirection = new Vector3d(-1, -1, 1);
        acDoc.Editor.UpdateTiledViewportsFromDatabase();

        // Save the new objects to the database
        acTrans.Commit();
    }
}