缩放对象
 
 

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 函数是在 X、Y 和 Z 方向等比缩放对象。缩放时用对象的尺寸乘以缩放比例。缩放比例大于 1 时将放大对象,缩放比例大于 0 小于 1 时将缩小对象。

NoteIf 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 the AutoCAD User's Guide.

更多关于进行缩放的详细信息,请参见《AutoCAD 用户手册》中的“调整对象的大小和形状”。

缩放多段线

This example creates a closed lightweight polyline and then scales the polyline by 0.5 from the base point (4,4.25,0).

本例创建一条闭合的优化多段线,然后以 0.5 的缩放比例及基点(4,4.25,0)调整该多段线。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("ScaleObject")> _
Public Sub ScaleObject()
  '' 获得当前文档和数据库   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, 2), 0, 0, 0)
      acPoly.AddVertexAt(1, New Point2d(1, 3), 0, 0, 0)
      acPoly.AddVertexAt(2, New Point2d(2, 3), 0, 0, 0)
      acPoly.AddVertexAt(3, New Point2d(3, 3), 0, 0, 0)
      acPoly.AddVertexAt(4, New Point2d(4, 4), 0, 0, 0)
      acPoly.AddVertexAt(5, New Point2d(4, 2), 0, 0, 0)
 
      '' 闭合多段线   Close the polyline
      acPoly.Closed = True
 
      '' 利用基点(4,4.25,0)及0.5的缩放比例缩小对象    Reduce the object by a factor of 0.5 
      '' using a base point of (4,4.25,0)
      acPoly.TransformBy(Matrix3d.Scaling(0.5, New Point3d(4, 4.25, 0)))
 
      '' 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction
      acBlkTblRec.AppendEntity(acPoly)
      acTrans.AddNewlyCreatedDBObject(acPoly, True)
 
      '' 保存新对象到数据库中   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("ScaleObject")]
public static void ScaleObject()
{
  // 获得当前文档和数据库   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, 2), 0, 0, 0);
      acPoly.AddVertexAt(1, new Point2d(1, 3), 0, 0, 0);
      acPoly.AddVertexAt(2, new Point2d(2, 3), 0, 0, 0);
      acPoly.AddVertexAt(3, new Point2d(3, 3), 0, 0, 0);
      acPoly.AddVertexAt(4, new Point2d(4, 4), 0, 0, 0);
      acPoly.AddVertexAt(5, new Point2d(4, 2), 0, 0, 0);
 
      // 闭合多段线   Close the polyline
      acPoly.Closed = true;
 
      // 利用基点(4,4.25,0)及0.5的缩放比例缩小对象    Reduce the object by a factor of 0.5 
      // using a base point of (4,4.25,0)
      acPoly.TransformBy(Matrix3d.Scaling(0.5, new Point3d(4, 4.25, 0)));
 
      // 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction
      acBlkTblRec.AppendEntity(acPoly);
      acTrans.AddNewlyCreatedDBObject(acPoly, true);
 
      // 保存新对象到数据库中   Save the new objects to the database
      acTrans.Commit();
  }
}
VBA/ActiveX 代码参考