開いたスプラインまたは閉じたスプラインのプロパティを編集でき、ポリラインに変換することさえできます。スプラインを開いたり閉じたり、制御点を変更したり、スプラインの方向を逆転したりするには、次のプロパティを使用します。
スプラインの多項表現を返します。
スプラインの端点の接線を方向ベクトルで返します。
スプラインを新しい許容差で既存の点に再フィットします。
スプラインの制御点の数を返します。
スプラインのフィット点の数を返します。
スプラインの開始接線を返します。
また次のメソッドを使用して、スプラインを編集できます。
指定したインデックスで、単一フィット点をスプラインに追加します。
スプラインの次数を指定した次数に増やします。
指定したインデックスで、スプラインの制御点を取得します(1 つの制御点だけを取得します)。NumControlPoints プロパティには、スプラインの制御点の数が含まれます。
指定したインデックスで、スプラインのフィット点を取得します(1 つのフィット点だけを取得します。スプラインのすべてのフィット点をクエリーするには、FitData プロパティを使用した後、GetFitPoints メンバー関数で返される FitData オブジェクトをクエリーします)。NumFitPoints プロパティには、スプラインのフィット点の数が含まれます。
指定されたインデックスで、スプラインのフィット点を削除します。
スプラインの方向を反転させます。
指定したインデックスでスプラインの制御点を設定します。
スプラインのフィット点を、指定したインデックスに設定します(1 つのフィット点だけを設定します。スプラインのすべてのフィット点を変更するには、FitPoints プロパティを使用します)。
制御点の重みを、指定したインデックスに設定します。
次の読み込み専用プロパティを使用すると、スプラインについての情報を取得することができます。
スプラインの閉じた領域の面積を取得します。
スプラインが閉じているか開いているかを示します。
スプラインの多項表現の次数を取得します。
指定したスプラインが周期的かどうかを指定します。
指定したスプラインが平面上にあるかどうかを指定します。
指定したスプラインが有理かどうかを指定します。
スプラインの制御点の数を取得します。
スプラインのフィット点の数を取得します。
次の例は、スプラインを作成し、次に最初の制御点を変更します。
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
[CommandMethod("EditSpline")]
public static void EditSpline()
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table 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 Point3d Collection
Point3dCollection acPt3dColl = new Point3dCollection();
acPt3dColl.Add(new Point3d(1, 1, 0));
acPt3dColl.Add(new Point3d(5, 5, 0));
acPt3dColl.Add(new Point3d(10, 0, 0));
// Set the start and end tangency
Vector3d acStartTan = new Vector3d(0.5, 0.5, 0);
Vector3d acEndTan = new Vector3d(0.5, 0.5, 0);
// Create a spline
using (Spline acSpline = new Spline(acPt3dColl,
acStartTan,
acEndTan, 4, 0))
{
// Set a control point
acSpline.SetControlPointAt(0, new Point3d(0, 3, 0));
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acSpline);
acTrans.AddNewlyCreatedDBObject(acSpline, true);
}
// Save the new objects to the database
acTrans.Commit();
}
}