调整对齐和网格对齐方式 (.NET)
网格是测量距离的视觉指南,而捕捉模式用于限制光标移动。除了设置网格和捕捉模式的间距外,还可以调整所用捕捉的旋转和类型。 如果需要沿特定对齐方式或角度绘制,可以旋转捕捉角度。捕捉角度旋转的中心点是捕捉基点。
注意:更改活动视口的对齐和网格设置后,应使用 Editor 对象的方法更新绘图区域的显示。UpdateTiledViewportsFromDatabase
捕捉和格网不会影响通过 AutoCAD .NET API 指定的点,但如果用户被要求使用 或 等方法输入输入,则会影响用户在绘图区域中指定的点。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 苏公网安备32011402011833)
GMT+8, 2025-11-1 10:08
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.