网格是测量距离的视觉指南,而捕捉模式用于限制光标移动。除了设置栅格和捕捉模式的间距外,您还可以调整旋转和使用的捕捉类型。 如果需要沿特定路线或角度绘制,可以旋转捕捉角度。捕捉角度旋转的中心点是捕捉基点。 注意:更改活动视口的捕捉和网格设置后,应使用 Editor 对象的方法更新绘图区域的显示。UpdateTiledViewportsFromDatabase
捕捉和栅格不会影响通过 AutoCAD .NET API 指定的点,但如果要求用户使用 asor 等方法输入输入,则会影响用户在绘图区域中指定的点。GetPointGetEntity 更改网格和捕捉设置本示例将对齐基点更改为 (1,1),将对齐旋转角度更改为 30 度。网格打开,间距调整,以便更改可见。 VB.NETImports 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 '' 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() End Using End Sub C#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(); } } VBA/ActiveX 代码参考Sub ChangeGridAndSnap() ' Turn on the grid for the active viewport ThisDrawing.ActiveViewport.GridOn = True ' Adjust the spacing of the grid to 1, 1 ThisDrawing.ActiveViewport.SetGridSpacing 1, 1 ' Turn on the snap mode for the active viewport ThisDrawing.ActiveViewport.SnapOn = True ' Adjust the snap spacing to 0.5, 0.5 ThisDrawing.ActiveViewport.SetSnapSpacing 0.5, 0.5 ' Change the snap base point to 1, 1 Dim newBasePoint(0 To 1) As Double newBasePoint(0) = 1: newBasePoint(1) = 1 ThisDrawing.ActiveViewport.SnapBasePoint = newBasePoint ' Change the snap rotation angle to 30 degrees (0.524 radians) Dim rotationAngle As Double rotationAngle = 0.524 ThisDrawing.ActiveViewport.SnapRotationAngle = rotationAngle ' Reset the viewport ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport End Sub |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )
GMT+8, 2024-5-19 13:50
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.