EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 564|回复: 0
打印 上一主题 下一主题

[资料] 创建和编辑AutoCAD实体(四) 编辑二维命名对象 (3)

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12404

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-8 15:40:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
5、Transform Objects变换对象
You move, scale, rotate and mirror an object using a 4 by 4 transformation matrix represented by a Matrix3d object and the TransformBy method. You can also use the GetTransformedCopy method to create a copy of an entity and then apply the transformation to the copy. The Matrix3d object is part of the Geometry namespace.
我们使用Matrix3d对象表示的4×4变换矩阵和TransformBy方法来对对象进行移动、缩放、旋转和镜像等变换操作。我们还可以使用GetTransformedCopy方法创建实体复本,然后对复本进行变换操作。Matrix3d对象是Geometry命名空间的组成部分。
The first three columns of the matrix specify scale and rotation. The fourth column of the matrix is a translation vector. The following table demonstrates the transformation matrix configuration, where R = Rotation and T = Translation:
矩阵的前三列确定缩放和旋转,矩阵的第四列是个平移向量。下表为变换矩阵的配置示范,其中R表示旋转,T表示平移:

Transformation matrix configuration变换矩阵配置
R00
R01
R02
T0
R10
R11
R12
T1
R20
R21
R22
T2
0
0
0
1
To transform an object, first initialize a Matrix3d object. You can initialize the transformation matrix using an array of doubles or starting with a matrix in which represents the World coordinate system or a user coordinate system. Once initialized, you then use the functions of the Matrix3d object to modify the scaling, rotation, or displacement transformation of the matrix.
要变换一个对象,首先初始化Matrix3d对象。我们可以使用一个双精度实数数组或者一个代表世界坐标系或用户坐标系的矩阵来初始化变换矩阵。完成初始化后,我们就可以使用Matrix3d对象的功能修改矩阵的缩放、旋转或平移变换。
After the transformation matrix is complete, apply the matrix to the object using the TransformBy method. The following line of code demonstrates applying a matrix (dMatrix) to an object (acObj):
完成变换矩阵后,使用TransformBy方法将变换矩阵应用在对象上就OK了。下面这行代码演示在对象acObj上应用矩阵dMatrix:
VB.NET
acObj.TransformBy(dMatrix)
C#
acObj.TransformBy(dMatrix);

Example of a rotation matrix 旋转矩阵示例

The following shows a single data array to define a transformation matrix, assigned to the variable dMatrix, which will rotate an entity by 90 degrees about the point (0, 0, 0).
下面演示用一维数组定义变换矩阵,赋值给变量dMatrix,让实体绕点(0, 0, 0)旋转90度。

Rotation Matrix: 90 degrees about point (0, 0, 0)
旋转矩阵: 绕点(0, 0, 0)旋转90度
0
-1
0
0
1
0
0
0
0
0
1
0
0
0
0
1

VB.NET
Initialize a transformation matrix with a data array in which contains the information to rotate an object 90 degrees.
使用数据数组初始化变换矩阵,数组包含旋转对象90度的数据。
Dim dMatrix(0 To 15) As Double

dMatrix(0) = 0.0
dMatrix(1) = -1.0
dMatrix(2) = 0.0
dMatrix(3) = 0.0
dMatrix(4) = 1.0
dMatrix(5) = 0.0
dMatrix(6) = 0.0
dMatrix(7) = 0.0
dMatrix(8) = 0.0
dMatrix(9) = 0.0
dMatrix(10) = 1.0
dMatrix(11) = 0.0
dMatrix(12) = 0.0
dMatrix(13) = 0.0
dMatrix(14) = 0.0
dMatrix(15) = 1.0
Dim acMat3d As Matrix3d = New Matrix3d(dMatrix)
Initialize a transformation matrix without a data array and use the Rotation function to return a transformation matrix that rotates an object 90 degrees.
不用数据数组初始化变换矩阵,而是用Rotation函数返回一个实现旋转对象90度的变换矩阵。
Dim acMat3d As Matrix3d = New Matrix3d()
Matrix3d.Rotation(Math.PI / 2,   curUCS.Zaxis,   New Point3d(0, 0, 0))

C#
Initialize a transformation matrix with a data array in which contains the information to rotate an object 90 degrees.
使用数据数组初始化变换矩阵,数组包含旋转对象90度的数据。
double[] dMatrix = new double[16];

dMatrix[0] = 0.0;
dMatrix[1] = -1.0;
dMatrix[2] = 0.0;
dMatrix[3] = 0.0;
dMatrix[4] = 1.0;
dMatrix[5] = 0.0;
dMatrix[6] = 0.0;
dMatrix[7] = 0.0;
dMatrix[8] = 0.0;
dMatrix[9] = 0.0;
dMatrix[10] = 1.0;
dMatrix[11] = 0.0;
dMatrix[12] = 0.0;
dMatrix[13] = 0.0;
dMatrix[14] = 0.0;
dMatrix[15] = 1.0;
Matrix3d acMat3d = new Matrix3d(dMatrix);

Initialize a transformation matrix without a data array and use the Rotation function to return a transformation matrix that rotates an object 90 degrees.
不用数据数组初始化变换矩阵,而是用Rotation函数返回一个实现旋转对象90度的变换矩阵。
Matrix3d acMat3d = new Matrix3d();
acMat3d = Matrix3d.Rotation(Math.PI / 2, curUCS.Zaxis, new Point3d(0, 0, 0));

Additional examples of transformation matrices 变换矩阵的其他示例

The following are more examples of transformation matrices:
下面为更多的变换矩阵示例

Rotation Matrix: 45 degrees about point (5, 5, 0)
旋转矩阵:围绕点(5, 5, 0)旋转45度
0.707107
-0.707107
0
5
0.707107
0.707107
0
-2.071068
0
0
1
0
0
0
0
1

Translation Matrix: move an entity by (10, 10, 0)
平移矩阵:沿向量(10, 10, 0)移动实体
1
0
0
10
0
1
0
10
0
0
1
0
0
0
0
1

Scaling Matrix: scale by 10,10 at point (0, 0, 0)
放大矩阵:以(0, 0, 0)为基点x、y、z方向均放大10倍
10
0
0
0
0
10
0
0
0
0
10
0
0
0
0
1

Scaling Matrix: scale by 10,10 at point (2, 2, 0)
放大矩阵:以(2, 2, 0)为基点x、y、z方向均放大10倍
10
0
0
-18
0
10
0
-18
0
0
10
0
0
0
0
1

Topics in this section
本小姐内容
·         Move Objects 移动对象
·         Rotate Objects 旋转对象
·         Mirror Objects 镜像对象
·         Scale Objects 缩放对象


5.1、Move Objects移动对象
You can move all drawing objects and attribute reference objects along a specified vector.
我们可以沿给定向量移动所有的图像对象及属性参照对象。
To move an object, use the Displacement function of a transformation matrix. This function requires a Vector3d object as input. If you do not know the vector that you need, you can create a Point3d object and then use the GetVectorTo method to return the vector between two points. The displacement vector indicates how far the given object is to be moved and in what direction.
移动对象使用变换矩阵的Displacement函数,该函数要求输入一个Vecto3d对象。如果不知道所需的向量,可以创建一个Point3d对象然后使用GetVectorTo方法返回两点间的向量。位移向量表示将给定对象移动多远及往哪个方向移动。

                               
登录/注册后可看大图
For more information about moving objects, see “Move Objects” in theAutoCAD User's Guide.
关于移动对象的更多内容见AutoCAD用户指南中“移动对象”一节。
Move a circle along a vector 沿向量移动一个圆

This example creates a circle and then moves that circle two units along theX axis.
本例创建一个圆,然后将这个圆沿X轴移动2个单位。
VB.NETImports Autodesk.AutoCAD.Runtime
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.ApplicationServices</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.DatabaseServices</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.Geometry</div>
  2. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><CommandMethod("MoveObject")> _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Public Sub MoveObject()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' Get the current document and database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Dim acCurDb As Database = acDoc.Database</div>
  3. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' Start a transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()</div>
  4. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Open the Block table for read</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acBlkTbl As BlockTable</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                   OpenMode.ForRead)</div>
  5. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Open the Block table record Model space for write</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acBlkTblRec As BlockTableRecord</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                      OpenMode.ForWrite)</div>
  6. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Create a circle that is at 2,2 with a radius of 0.5</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acCirc As Circle = New Circle()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acCirc.Center = New Point3d(2, 2, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acCirc.Radius = 0.5</div>
  7. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Create a matrix and move the circle using a vector from (0,0,0) to (2,0,0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acPt3d As Point3d = New Point3d(0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acVec3d As Vector3d = acPt3d.GetVectorTo(New Point3d(2, 0, 0))</div>
  8. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acCirc.TransformBy(Matrix3d.Displacement(acVec3d))</div>
  9. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acCirc)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acCirc, True)</div>
  10. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Save the new objects to the database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.Commit()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  End Using</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">End Sub</div>
复制代码
C#using Autodesk.AutoCAD.Runtime;
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.ApplicationServices;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.DatabaseServices;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.Geometry;</div>
  2. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">[CommandMethod("MoveObject")]</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">public static void MoveObject()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">{</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  // Get the current document and database获取当前文档和数据库</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Document acDoc = Application.DocumentManager.MdiActiveDocument;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Database acCurDb = acDoc.Database;</div>
  3. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  // Start a transaction启动事务</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  {</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Open the Block table for read以读打开块表</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      BlockTable acBlkTbl;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                   OpenMode.ForRead) as BlockTable;</div>
  4. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Open the Block table record Model space for write</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // 以写打开块表记录模型空间</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      BlockTableRecord acBlkTblRec;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                      OpenMode.ForWrite) as BlockTableRecord;</div>
  5. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Create a circle that is at 2,2 with a radius of 0.5</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // 创建圆,圆心2,2半径0.5</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Circle acCirc = new Circle();</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acCirc.Center = new Point3d(2, 2, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acCirc.Radius = 0.5;</div>
  6. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Create a matrix and move the circle using a vector from (0,0,0) to (2,0,0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // 创建一个矩阵,使用(0,0,0)到(2,0,0)的向量移动圆</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Point3d acPt3d = new Point3d(0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Vector3d acVec3d = acPt3d.GetVectorTo(new Point3d(2, 0, 0));</div>
  7. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acCirc.TransformBy(Matrix3d.Displacement(acVec3d));</div>
  8. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // 添加对象到块表记录和事务</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acCirc);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acCirc, true);</div>
  9. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Save the new objects to the database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // 提交事务</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.Commit();</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  }</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">}</div>
复制代码
VBA/ActiveX Code ReferenceSub MoveObject()
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' Create the circle</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim circleObj As AcadCircle</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim center(0 To 2) As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim radius As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    center(0) = 2#: center(1) = 2#: center(2) = 0#</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    radius = 0.5</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Set circleObj = ThisDrawing.ModelSpace. _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                  AddCircle(center, radius)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ZoomAll</div>
  2. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' Define the points that make up the move vector.</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' The move vector will move the circle 2 units</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' along the x axis.</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim point1(0 To 2) As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim point2(0 To 2) As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    point1(0) = 0: point1(1) = 0: point1(2) = 0</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    point2(0) = 2: point2(1) = 0: point2(2) = 0</div>
  3. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' Move the circle</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    circleObj.Move point1, point2</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    circleObj.Update</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">End Sub</div>
复制代码
5.2、Rotate Objects旋转对象
You can rotate all drawing objects and attribute reference objects.
我们可以旋转所有的图像对象及属性参照对象。
To rotate an object, use the Rotation function of a transformation matrix. This function requires a rotation angle represented in radians, an axis of rotation, and a base point. The axis of rotation must be expressed as a Vector3d object and the base point as a Point3d object. This angle determines how far an object rotates around the base point relative to its current location.
旋转对象使用变换矩阵的Rotation函数,该函数要求输入用弧度表示的旋转角度、旋转轴和旋转基点。旋转轴用Vector3d对象表示,旋转基点用Point3d对象表示。旋转角度表示相对于当前位置将对象围绕基点旋转多远。

                               
登录/注册后可看大图

For more information about rotating objects, see “Rotate Objects” in theUser's Guide.
关于旋转对象的更多内容见AutoCAD用户指南中“旋转对象”一节。
Rotate a polyline about a base point 绕基点旋转多段线

This example creates a closed lightweight polyline, and then rotates the polyline 45 degrees about the base point (4, 4.25, 0).
本例创建一个闭合轻量级多段线,然后将其绕点(4, 4.25, 0)旋转45度。
VB.NETImports Autodesk.AutoCAD.Runtime
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.ApplicationServices</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.DatabaseServices</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.Geometry</div>
  2. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><CommandMethod("RotateObject")> _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Public Sub RotateObject()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' Get the current document and database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Dim acCurDb As Database = acDoc.Database</div>
  3. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' Start a transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()</div>
  4. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Open the Block table for read</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acBlkTbl As BlockTable</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                   OpenMode.ForRead)</div>
  5. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Open the Block table record Model space for write</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acBlkTblRec As BlockTableRecord</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                      OpenMode.ForWrite)</div>
  6. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Create a lightweight polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acPoly As Polyline = New Polyline()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(0, New Point2d(1, 2), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(1, New Point2d(1, 3), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(2, New Point2d(2, 3), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(3, New Point2d(3, 3), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(4, New Point2d(4, 4), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(5, New Point2d(4, 2), 0, 0, 0)</div>
  7. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Close the polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.Closed = True</div>
  8. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim curUCSMatrix As Matrix3d = acDoc.Editor.CurrentUserCoordinateSystem</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim curUCS As CoordinateSystem3d = curUCSMatrix.CoordinateSystem3d</div>
  9. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Rotate the polyline 45 degrees, around the Z-axis of the current UCS</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' using a base point of (4,4.25,0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.TransformBy(Matrix3d.Rotation(0.7854, _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                           curUCS.Zaxis, _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                           New Point3d(4, 4.25, 0)))</div>
  10. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acPoly)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acPoly, True)</div>
  11. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Save the new objects to the database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.Commit()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  End Using</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">End Sub</div>
复制代码
C#using Autodesk.AutoCAD.Runtime;
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.ApplicationServices;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.DatabaseServices;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.Geometry;</div>
  2. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">[CommandMethod("RotateObject")]</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">public static void RotateObject()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">{</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  // Get the current document and database获取当前文档和数据库</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Document acDoc = Application.DocumentManager.MdiActiveDocument;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Database acCurDb = acDoc.Database;</div>
  3. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  // Start a transaction启动事务</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  {</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Open the Block table for read以读打开块表</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      BlockTable acBlkTbl;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                   OpenMode.ForRead) as BlockTable;</div>
  4. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Open the Block table record Model space for write以写打开块表记录模型空间</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      BlockTableRecord acBlkTblRec;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                      OpenMode.ForWrite) as BlockTableRecord;</div>
  5. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Create a lightweight polyline创建轻量级多段线</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Polyline acPoly = new Polyline();</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(0, new Point2d(1, 2), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(1, new Point2d(1, 3), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(2, new Point2d(2, 3), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(3, new Point2d(3, 3), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(4, new Point2d(4, 4), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(5, new Point2d(4, 2), 0, 0, 0);</div>
  6. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Close the polyline闭合多段线</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.Closed = true;</div>
  7. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Matrix3d curUCSMatrix = acDoc.Editor.CurrentUserCoordinateSystem;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      CoordinateSystem3d curUCS = curUCSMatrix.CoordinateSystem3d;</div>
  8. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Rotate the polyline 45 degrees, around the Z-axis of the current UCS</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // using a base point of (4,4.25,0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      //绕当前UCS的Z轴将多段线旋转45度,基点(4,4.25,0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.TransformBy(Matrix3d.Rotation(0.7854,</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                           curUCS.Zaxis,</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                           new Point3d(4, 4.25, 0)));</div>
  9. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      //添加到块表记录和事务</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acPoly);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acPoly, true);</div>
  10. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Save the new objects to the database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // 保存到数据库</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.Commit();</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  }</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">}</div>
复制代码
VBA/ActiveX Code ReferenceSub RotateObject()
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' Create the polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim plineObj As AcadLWPolyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim points(0 To 11) As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(0) = 1: points(1) = 2</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(2) = 1: points(3) = 3</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(4) = 2: points(5) = 3</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(6) = 3: points(7) = 3</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(8) = 4: points(9) = 4</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(10) = 4: points(11) = 2</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Set plineObj = ThisDrawing.ModelSpace. _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                    AddLightWeightPolyline(points)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    plineObj.Closed = True</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ZoomAll</div>
  2. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' Define the rotation of 45 degrees about a</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' base point of (4, 4.25, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim basePoint(0 To 2) As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim rotationAngle As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    basePoint(0) = 4: basePoint(1) = 4.25: basePoint(2) = 0</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    rotationAngle = 0.7853981   ' 45 degrees</div>
  3. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' Rotate the polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    plineObj.Rotate basePoint, rotationAngle</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    plineObj.Update</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">End Sub</div>
复制代码
5.3、Mirror Objects镜像对象
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.
使用系统变量MIRRTEXT来管理文字对象的翻转属性。MIRRTEXT的默认设置为开(1),结果是文字对象和其他任何对象一样被翻转过来。MIRRTEXT设置为关(0)时,文字不被翻转。可以使用GetSystemVariable方法和SetSystemVariable方法查询和设置MIRRTEXT变量。


                               
登录/注册后可看大图
镜像前          镜像后(MIRRTEXT=1)     镜像后(MIRRTEXT=0)

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.
我们可以镜像图纸空间的视口对象,虽然这样做对模型空间的视图和对象没有作用。
For more information about mirroring objects, see “Copy, Offset, or Mirror Objects” in theAutoCAD User's Guide.
关于镜像对象的更多内容见AutoCAD用户指南中“复制、偏移或镜像对象”一节。
Mirror a polyline about an axis 绕轴线镜像一个多段线

This example creates a lightweight polyline and mirrors that polyline about an axis. The newly created polyline is colored blue.
本例创建一个轻量级多段线,然后绕轴线对其进行镜像。得到的新对象改为蓝色。
VB.NETImports Autodesk.AutoCAD.Runtime
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.ApplicationServices</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.DatabaseServices</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.Geometry</div>
  2. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><CommandMethod("MirrorObject")> _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Public Sub MirrorObject()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' Get the current document and database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Dim acCurDb As Database = acDoc.Database</div>
  3. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' Start a transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()</div>
  4. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Open the Block table for read</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acBlkTbl As BlockTable</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                   OpenMode.ForRead)</div>
  5. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Open the Block table record Model space for write</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acBlkTblRec As BlockTableRecord</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                      OpenMode.ForWrite)</div>
  6. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Create a lightweight polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acPoly As Polyline = New Polyline()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(0, New Point2d(1, 1), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(1, New Point2d(1, 2), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(2, New Point2d(2, 2), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(3, New Point2d(3, 2), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(4, New Point2d(4, 4), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(5, New Point2d(4, 1), 0, 0, 0)</div>
  7. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Create a bulge of -2 at vertex 1</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.SetBulgeAt(1, -2)</div>
  8. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Close the polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.Closed = True</div>
  9. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acPoly)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acPoly, True)</div>
  10. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Create a copy of the original polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acPolyMirCopy As Polyline = acPoly.Clone()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPolyMirCopy.ColorIndex = 5</div>
  11. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Define the mirror line</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acPtFrom As Point3d = New Point3d(0, 4.25, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acPtTo As Point3d = New Point3d(4, 4.25, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acLine3d As Line3d = New Line3d(acPtFrom, acPtTo)</div>
  12. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Mirror the polyline across the X axis</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPolyMirCopy.TransformBy(Matrix3d.Mirroring(acLine3d))</div>
  13. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acPolyMirCopy)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acPolyMirCopy, True)</div>
  14. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Save the new objects to the database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.Commit()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  End Using</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">End Sub</div>
复制代码
C#using Autodesk.AutoCAD.Runtime;
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.ApplicationServices;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.DatabaseServices;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.Geometry;</div>
  2. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">[CommandMethod("MirrorObject")]</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">public static void MirrorObject()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">{</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  // Get the current document and database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Document acDoc = Application.DocumentManager.MdiActiveDocument;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Database acCurDb = acDoc.Database;</div>
  3. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  // Start a transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  {</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Open the Block table for read</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      BlockTable acBlkTbl;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                   OpenMode.ForRead) as BlockTable;</div>
  4. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Open the Block table record Model space for write</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      BlockTableRecord acBlkTblRec;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                      OpenMode.ForWrite) as BlockTableRecord;</div>
  5. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Create a lightweight polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Polyline acPoly = new Polyline();</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(0, new Point2d(1, 1), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(1, new Point2d(1, 2), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(2, new Point2d(2, 2), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(3, new Point2d(3, 2), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(4, new Point2d(4, 4), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(5, new Point2d(4, 1), 0, 0, 0);</div>
  6. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Create a bulge of -2 at vertex 1</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      //设置顶点1到顶点2间的多段线段的凸度为-2</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.SetBulgeAt(1, -2);</div>
  7. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Close the polyline闭合多段线</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.Closed = true;</div>
  8. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acPoly);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acPoly, true);</div>
  9. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Create a copy of the original polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // 创建原多段线的复本</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Polyline acPolyMirCopy = acPoly.Clone() as Polyline;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPolyMirCopy.ColorIndex = 5;</div>
  10. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Define the mirror line定义镜像线</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Point3d acPtFrom = new Point3d(0, 4.25, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Point3d acPtTo = new Point3d(4, 4.25, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Line3d acLine3d = new Line3d(acPtFrom, acPtTo);</div>
  11. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Mirror the polyline across the X axis沿X轴方向翻转多段线</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPolyMirCopy.TransformBy(Matrix3d.Mirroring(acLine3d));</div>
  12. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acPolyMirCopy);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acPolyMirCopy, true);</div>
  13. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Save the new objects to the database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.Commit();</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  }</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">}</div>
复制代码
VBA/ActiveX Code ReferenceSub MirrorObject()
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' Create the polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim plineObj As AcadLWPolyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim points(0 To 11) As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(0) = 1: points(1) = 1</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(2) = 1: points(3) = 2</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(4) = 2: points(5) = 2</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(6) = 3: points(7) = 2</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(8) = 4: points(9) = 4</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    points(10) = 4: points(11) = 1</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Set plineObj = ThisDrawing.ModelSpace. _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                       AddLightWeightPolyline(points)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    plineObj.SetBulge 1, -2</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    plineObj.Closed = True</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ZoomAll</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' Define the mirror axis</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim point1(0 To 2) As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim point2(0 To 2) As Double</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    point1(0) = 0: point1(1) = 4.25: point1(2) = 0</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    point2(0) = 4: point2(1) = 4.25: point2(2) = 0</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ' Mirror the polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Dim mirrorObj As AcadLWPolyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    Set mirrorObj = plineObj.Mirror(point1, point2)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    mirrorObj.color = acBlue</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">    ZoomAll</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">End Sub</div>
复制代码
5.4、Scale Objects缩放对象
You scale an object by specifying a base point and scale factor based on the current drawing units. You can scale all drawing objects, as well as attribute reference objects.
我们通过指定一个基准点和基于当前绘图单位的缩放系数来缩放对象。我们可以缩放任何对象,包括属性参照对象。
To scale an object, use the Scaling function of a transformation matrix. This function requires a numeric value for the scale factor of the object and a Point3d object for the base point of the scaling operation. The Scaling function scales the object equally in the X, Y, and Z directions. The dimensions of the object are multiplied by the scale factor. A scale factor greater than 1 enlarges the object. A scale factor between 0 and 1 reduces the object.
缩放对象使用变换矩阵的Scaling函数,该函数需要输入一个数值作为对象的缩放系数,还需要输入一个Point3d对象作为缩放操作的基点。Scaling函数在XYZ轴向上将对象缩放相同的倍数。对象的尺寸乘以缩放系数,缩放系数大于1则放大对象,缩放系数小于1则缩小对象。

                               
登录/注册后可看大图
Note If you need to scale an object non-uniformly, you need to initialize a transformation matrix using the appropriate data array and then use the TransformBy method of the object. For more information on initializing a transformation matrix with a data array, see Transform Objects.
注意 如果要采用不一致的缩放系数缩放对象,需使用相应的数据数组初始化变换矩阵,然后调用对象的TransformBy方法。详见前面“变换对象”的内容
For more information about scaling, see “Resize or Reshape Objects” in theAutoCAD User's Guide.
关于缩放的更多内容,见AutoCAD用户指南中“更改对象的形状和大小”一节。
Scale a polyline 修改多段线的大小

This example creates a closed lightweight polyline and then scales the polyline by 0.5 from the base point (4, 4.25, 0).
本例创建一个闭合多段线,然后以(4, 4.25, 0)为基点将多段线缩小0.5倍。

VB.NET
  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><strong></strong></div>
  2. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.Runtime</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.ApplicationServices</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.DatabaseServices</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Imports Autodesk.AutoCAD.Geometry</div>
  3. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; "><CommandMethod("ScaleObject")> _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">Public Sub ScaleObject()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' Get the current document and database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Dim acCurDb As Database = acDoc.Database</div>
  4. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  '' Start a transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()</div>
  5. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Open the Block table for read</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acBlkTbl As BlockTable</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                   OpenMode.ForRead)</div>
  6. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Open the Block table record Model space for write</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acBlkTblRec As BlockTableRecord</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                      OpenMode.ForWrite)</div>
  7. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Create a lightweight polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Dim acPoly As Polyline = New Polyline()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(0, New Point2d(1, 2), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(1, New Point2d(1, 3), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(2, New Point2d(2, 3), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(3, New Point2d(3, 3), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(4, New Point2d(4, 4), 0, 0, 0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(5, New Point2d(4, 2), 0, 0, 0)</div>
  8. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Close the polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.Closed = True</div>
  9. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Reduce the object by a factor of 0.5</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' using a base point of (4,4.25,0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.TransformBy(Matrix3d.Scaling(0.5, New Point3d(4, 4.25, 0)))</div>
  10. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acPoly)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acPoly, True)</div>
  11. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      '' Save the new objects to the database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.Commit()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  End Using</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">End Sub</div>
复制代码
C#

  1. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.Runtime;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.ApplicationServices;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.DatabaseServices;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">using Autodesk.AutoCAD.Geometry;</div>
  2. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">[CommandMethod("ScaleObject")]</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">public static void ScaleObject()</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">{</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  // Get the current document and database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Document acDoc = Application.DocumentManager.MdiActiveDocument;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  Database acCurDb = acDoc.Database;</div>
  3. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  // Start a transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  {</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Open the Block table for read</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      BlockTable acBlkTbl;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                   OpenMode.ForRead) as BlockTable;</div>
  4. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Open the Block table record Model space for write</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      BlockTableRecord acBlkTblRec;</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">                                      OpenMode.ForWrite) as BlockTableRecord;</div>
  5. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Create a lightweight polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      Polyline acPoly = new Polyline();</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(0, new Point2d(1, 2), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(1, new Point2d(1, 3), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(2, new Point2d(2, 3), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(3, new Point2d(3, 3), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(4, new Point2d(4, 4), 0, 0, 0);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.AddVertexAt(5, new Point2d(4, 2), 0, 0, 0);</div>
  6. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Close the polyline</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.Closed = true;</div>
  7. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Reduce the object by a factor of 0.5</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // using a base point of (4,4.25,0)</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acPoly.TransformBy(Matrix3d.Scaling(0.5, new Point3d(4, 4.25, 0)));</div>
  8. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Add the new object to the block table record and the transaction</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acBlkTblRec.AppendEntity(acPoly);</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.AddNewlyCreatedDBObject(acPoly, true);</div>
  9. <div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      // Save the new objects to the database</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">      acTrans.Commit();</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">  }</div><div align="left" style="color: rgb(51, 51, 51); font-family: Arial; ">}</div>
复制代码
VBA/ActiveX Code Reference

  1. <div align="left">Sub ScaleObject()</div><div align="left">    ' Create the polyline</div><div align="left">    Dim plineObj As AcadLWPolyline</div><div align="left">    Dim points(0 To 11) As Double</div><div align="left">    points(0) = 1: points(1) = 2</div><div align="left">    points(2) = 1: points(3) = 3</div><div align="left">    points(4) = 2: points(5) = 3</div><div align="left">    points(6) = 3: points(7) = 3</div><div align="left">    points(8) = 4: points(9) = 4</div><div align="left">    points(10) = 4: points(11) = 2</div><div align="left">    Set plineObj = ThisDrawing.ModelSpace. _</div><div align="left">                                 AddLightWeightPolyline(points)</div><div align="left">    plineObj.Closed = True</div><div align="left">    ZoomAll</div><div align="left">    ' Define the scale</div><div align="left">    Dim basePoint(0 To 2) As Double</div><div align="left">    Dim scalefactor As Double</div><div align="left">    basePoint(0) = 4: basePoint(1) = 4.25: basePoint(2) = 0</div><div align="left">    scalefactor = 0.5</div><div align="left">    ' Scale the polyline</div><div align="left">    plineObj.ScaleEntity basePoint, scalefactor</div><div align="left">    plineObj.Update</div><div align="left">End Sub</div>
复制代码

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对
工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-16 15:55

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表