操作方法
在CAD操作中SCALE缩放命令的用法:输入SC或SCALE命令,选择要缩入的对象-选择基点-输入缩放比例参数-空格完成。
代码实现
使用API实现的关键点:调用Entity的TransformBy方法。如下:
/// <summary>
/// 缩放
/// </summary>
/// <param name="id">数据ID</param>
/// <param name="basePoint">基点</param>
/// <param name="scale">缩放比例参数-</param>
public static void Scale(ObjectId id, Point3d basePoint, double scale)
{
Matrix3d transform = Matrix3d.Scaling(scale, basePoint);
Database db = id.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
if (ent != null)
{
ent.TransformBy(transform);
}
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
AcadApp.ShowAlertDialog(ex.Message);
}
}
}