Mirroring flips an object along an axis or mirror line. You can mirror all drawing objects.
镜像可以绕着轴或镜像线翻转一个对象。可以镜像所有图形对象。
To mirror an object, use the Mirroring function of a transformation matrix. This function requires a Point3d, Plane, or Line3d object to define the mirror line. Since mirroring is done with a transformation matrix, a new object is not created. If you want to maintain the original object, you will need to create a copy of the object first and then mirror it.
要镜像对象,请使用一个转换矩阵的 Mirroring 函数。这个函数需要一个 Point3d、Plane 或 Line3d 对象用来定义镜像线。由于镜像是通过转换矩阵来完成的,所以不会创建新对象。如果想操作原始对象,就需要首先创建一个对象的副本然后再镜像它。
To manage the reflection properties of Text objects, use the MIRRTEXT system variable. The default setting of MIRRTEXT is On (1), which causes Text objects to be mirrored just as any other object. When MIRRTEXT is Off (0), text is not mirrored. Use the GetSystemVariable and SetSystemVariable methods to query and set the MIRRTEXT setting.
要管理 Text 对象的反射特性,请使用 MIRRTEXT 系统变量。MIRRTEXT 的默认设置为开 (1),这将导致 Text 对象像其他对象一样也被镜像。当 MIRRTEXT 设置为关 (0) 时,不会镜像文字。使用 GetSystemVariable 和 SetSystemVariable 方法可以查询和设置 MIRRTEXT 设置。
You can mirror a Viewport object in paper space, although doing so has no effect on its model space view or on model space objects.
用户可以在图纸空间中镜像 Viewport 对象,虽然这样做并不会影响其模型空间视图或模型空间对象。
For more information about mirroring objects, see “Copy, Offset, or Mirror Objects” in the AutoCAD User's Guide.
更多关于镜像对象的详细信息,请参见《AutoCAD 用户手册》中的“复制、偏移或镜像对象”。
This example creates a lightweight polyline and mirrors that polyline about an axis. The newly created polyline is colored blue.
本例创建一条优化多段线,然后绕一个轴镜像该多段线。新创建的多段线会着上蓝色。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("MirrorObject")> _
Public Sub MirrorObject()
'' 获得当前文档和数据库 Get the current document and 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 Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _
OpenMode.ForRead)
'' 以写方式打开模型空间块表记录 Open the Block table record Model space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
OpenMode.ForWrite)
'' 创建一条轻量多段线 Create a lightweight polyline
Dim acPoly As Polyline = New Polyline()
acPoly.SetDatabaseDefaults()
acPoly.AddVertexAt(0, New Point2d(1, 1), 0, 0, 0)
acPoly.AddVertexAt(1, New Point2d(1, 2), 0, 0, 0)
acPoly.AddVertexAt(2, New Point2d(2, 2), 0, 0, 0)
acPoly.AddVertexAt(3, New Point2d(3, 2), 0, 0, 0)
acPoly.AddVertexAt(4, New Point2d(4, 4), 0, 0, 0)
acPoly.AddVertexAt(5, New Point2d(4, 1), 0, 0, 0)
'' 在顶点1处创建一个-2的凸度 Create a bulge of -2 at vertex 1
acPoly.SetBulgeAt(1, -2)
'' 闭合多段线 Close the polyline
acPoly.Closed = True
'' 添加新对象到块表记录和事务中 Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPoly)
acTrans.AddNewlyCreatedDBObject(acPoly, True)
'' 创建一个原始多段线的副本 Create a copy of the original polyline
Dim acPolyMirCopy As Polyline = acPoly.Clone()
acPolyMirCopy.ColorIndex = 5
'' 定义镜像线 Define the mirror line
Dim acPtFrom As Point3d = New Point3d(0, 4.25, 0)
Dim acPtTo As Point3d = New Point3d(4, 4.25, 0)
Dim acLine3d As Line3d = New Line3d(acPtFrom, acPtTo)
'' 通过 X 轴镜像多段线 Mirror the polyline across the X axis
acPolyMirCopy.TransformBy(Matrix3d.Mirroring(acLine3d))
'' 添加新对象到块表记录和事务中 Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPolyMirCopy)
acTrans.AddNewlyCreatedDBObject(acPolyMirCopy, True)
'' 保存新对象到数据库中 Save the new objects to the database
acTrans.Commit()
End Using
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
[CommandMethod("MirrorObject")]
public static void MirrorObject()
{
// 获得当前文档和数据库 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 lightweight polyline
Polyline acPoly = new Polyline();
acPoly.SetDatabaseDefaults();
acPoly.AddVertexAt(0, new Point2d(1, 1), 0, 0, 0);
acPoly.AddVertexAt(1, new Point2d(1, 2), 0, 0, 0);
acPoly.AddVertexAt(2, new Point2d(2, 2), 0, 0, 0);
acPoly.AddVertexAt(3, new Point2d(3, 2), 0, 0, 0);
acPoly.AddVertexAt(4, new Point2d(4, 4), 0, 0, 0);
acPoly.AddVertexAt(5, new Point2d(4, 1), 0, 0, 0);
// 在顶点1处创建一个-2的凸度 Create a bulge of -2 at vertex 1
acPoly.SetBulgeAt(1, -2);
// 闭合多段线 Close the polyline
acPoly.Closed = true;
// 添加新对象到块表记录和事务中 Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPoly);
acTrans.AddNewlyCreatedDBObject(acPoly, true);
// 创建一个原始多段线的副本 Create a copy of the original polyline
Polyline acPolyMirCopy = acPoly.Clone() as Polyline;
acPolyMirCopy.ColorIndex = 5;
// 定义镜像线 Define the mirror line
Point3d acPtFrom = new Point3d(0, 4.25, 0);
Point3d acPtTo = new Point3d(4, 4.25, 0);
Line3d acLine3d = new Line3d(acPtFrom, acPtTo);
// 通过 X 轴镜像多段线 Mirror the polyline across the X axis
acPolyMirCopy.TransformBy(Matrix3d.Mirroring(acLine3d));
// 添加新对象到块表记录和事务中 Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPolyMirCopy);
acTrans.AddNewlyCreatedDBObject(acPolyMirCopy, true);
// 保存新对象到数据库中 Save the new objects to the database
acTrans.Commit();
}
}