The grid is a visual guideline to measure distances, while Snap mode is used to restrict cursor movement. In addition to setting the spacing for the grid and Snap mode, you can adjust the rotation and type of snap used.
可以使用栅格作为直观的定位基准,并打开“捕捉”模式以限制光标的移动。除设置栅格间距和捕捉模式外,还可以调整捕捉的旋转角和类型。
If you need to draw along a specific alignment or angle, you can rotate the snap angle. The center point of the snap angle rotation is the snap base point.
如果需要沿特定对齐方向或角度绘图,可以旋转捕捉角度。捕捉角度旋转的中心点即是捕捉基点。
NoteAfter changing the snap and grid settings for the active viewport, you should use the UpdateTiledViewportsFromDatabase method of the Editor object to update the display of the drawing area.
注意修改活动视口的捕捉和栅格设置后,应用使用 Editor 对象的 UpdateTiledViewportsFromDatabase 方法更新图形区域的显示。
Snap and grid do not affect points specified through the .NET API, but do affect points specified in the drawing area by the user if they are requested to enter input using methods such as GetPoint or GetEntity. See “Adjust Grid and Grid Snap” in the AutoCAD User's Guide for more information on using and setting snaps and grids.
捕捉和栅格不影响通过 .NET API 指定点,但影响由用户在图形区域中指定点,如果使用像 GetPoint 或 GetEntity 之类的方法请求用户输入和选择时会受影响。有关使用和设置捕捉和栅格的详细信息,请参见《AutoCAD 用户手册》中的“调整栅格和栅格捕捉”。
This example changes the snap base point to (1,1) and the snap rotation angle to 30 degrees. The grid is turned on the spacing is adjusted so that the changes are visible.
本例将捕捉基点更改为 (1,1),并将捕捉旋转角更改为 30 度,同时打开栅格以显示这些更改。
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("ChangeGridAndSnap")> _
Public Sub ChangeGridAndSnap()
'' 获得当前数据库 Get the current database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
''启动一个事务 Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' 打开活动视口 Open the active viewport
Dim acVportTblRec As ViewportTableRecord
acVportTblRec = acTrans.GetObject(acDoc.Editor.ActiveViewportId, _
OpenMode.ForWrite)
'' 为活动视口打开栅格 Turn on the grid for the active viewport
acVportTblRec.GridEnabled = True
'' 调整栅格的间距为 1,1 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
'' 调整捕捉间距为 0.5,0.5 Adjust the snap spacing to 0.5, 0.5
acVportTblRec.SnapIncrements = New Point2d(0.5, 0.5)
'' 修改捕捉基点到 1,1 Change the snap base point to 1, 1
acVportTblRec.SnapBase = New Point2d(1, 1)
'' 修改捕捉旋转角度为30度 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()
End Using
End Sub
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;
// 调整栅格的间距为 1,1 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;
// 调整捕捉间距为 0.5,0.5 Adjust the snap spacing to 0.5, 0.5
acVportTblRec.SnapIncrements = new Point2d(0.5, 0.5);
// 修改捕捉基点到 1,1 Change the snap base point to 1, 1
acVportTblRec.SnapBase = new Point2d(1, 1);
// 修改捕捉旋转角度为30度 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();
}
}