グリッドが距離を計測するための目に見えるガイドラインであるのに対し、スナップ モードはカーソルの動きを制限するために使用されます。グリッドおよびスナップ モードの間隔を設定するだけでなく、使用するスナップの回転と種類を調整できます。
特定の位置や角度に沿って作図する必要がある場合、スナップ角度を回転できます。スナップ角度回転の中心点は、スナップ基点です。
スナップとグリッドは AutoCAD .NET API を使用して指定された点には影響しませんが、ユーザーが作図領域で指定した、GetPoint や GetEntity などのメソッドを使用して入力するように要求された場合の点には影響します。
以下の例は、スナップ基点を(1,1)、スナップ回転角度を 30 度に変更します。グリッドがオンにされ、変更が表示されるように間隔が調整されます。
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
[CommandMethod("ChangeGridAndSnap")]
public static void ChangeGridAndSnap()
{
// Get the current database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the active viewport
ViewportTableRecord acVportTblRec;
acVportTblRec = acTrans.GetObject(acDoc.Editor.ActiveViewportId,
OpenMode.ForWrite) as ViewportTableRecord;
// Turn on the grid for the active viewport
acVportTblRec.GridEnabled = true;
// Adjust the spacing of the grid to 1, 1
acVportTblRec.GridIncrements = new Point2d(1, 1);
// Turn on the snap mode for the active viewport
acVportTblRec.SnapEnabled = true;
// Adjust the snap spacing to 0.5, 0.5
acVportTblRec.SnapIncrements = new Point2d(0.5, 0.5);
// Change the snap base point to 1, 1
acVportTblRec.SnapBase = new Point2d(1, 1);
// Change the snap rotation angle to 30 degrees (0.524 radians)
acVportTblRec.SnapAngle = 0.524;
// Update the display of the tiled viewport
acDoc.Editor.UpdateTiledViewportsFromDatabase();
// Commit the changes and dispose of the transaction
acTrans.Commit();
}
}