镜像对象 (.NET)
镜像沿轴或镜像线翻转对象。可以镜像所有图形对象。 若要镜像对象,请使用变换矩阵的函数。此函数需要 、 或 对象来定义镜像线。由于镜像是使用变换矩阵完成的,因此不会创建新对象。如果要维护原始对象,则需要先创建对象的副本,然后对其进行镜像。MirroringPoint3dPlaneLine3d ![]() 若要管理对象的反射属性,请使用 MIRRTEXT 系统变量。MIRRTEXT 的默认设置为 On (1),这会导致对象像任何其他对象一样镜像。当 MIRRTEXT 关闭 (0) 时,文本不会镜像。使用 and 方法查询和设置 MIRRTEXT 设置。TextTextGetSystemVariableSetSystemVariable ![]() 您可以在图纸空间中镜像 Viewport 对象,但这样做不会影响其模型空间视图或模型空间对象。 绕轴镜像折线本示例创建一条轻量级折线,并围绕轴镜像该折线。新创建的折线颜色为蓝色。 VB.NETImports 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
Using acPoly As Polyline = New Polyline()
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)
'' 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)
'' 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)
End Using
'' Save the new objects to the database
acTrans.Commit()
End Using
End Sub
C#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
using (Polyline acPoly = new Polyline())
{
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);
// 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);
// 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();
}
}
VBA/ActiveX 代码参考Sub MirrorObject()
' Create the polyline
Dim plineObj As AcadLWPolyline
Dim points(0 To 11) As Double
points(0) = 1: points(1) = 1
points(2) = 1: points(3) = 2
points(4) = 2: points(5) = 2
points(6) = 3: points(7) = 2
points(8) = 4: points(9) = 4
points(10) = 4: points(11) = 1
Set plineObj = ThisDrawing.ModelSpace. _
AddLightWeightPolyline(points)
plineObj.SetBulge 1, -2
plineObj.Closed = True
ZoomAll
' Define the mirror axis
Dim point1(0 To 2) As Double
Dim point2(0 To 2) As Double
point1(0) = 0: point1(1) = 4.25: point1(2) = 0
point2(0) = 4: point2(1) = 4.25: point2(2) = 0
' Mirror the polyline
Dim mirrorObj As AcadLWPolyline
Set mirrorObj = plineObj.Mirror(point1, point2)
mirrorObj.color = acBlue
ZoomAll
End Sub
相关概念父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-30 07:09
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.