C# 如何对多段线内的一组图元应用变换?

C# 如何对多段线内的一组图元应用变换?,c#,autocad-plugin,C#,Autocad Plugin,在要重新缩放的多段线图元中有一组图元对象。我创建了Extents3d对象来重新缩放对象,以避免逐个重新缩放对象,但它不起作用: Document document = Application.DocumentManager.MdiActiveDocument; Database database = document.Database; using(Transaction transaction = database.TransactionManager.StartTransaction()

在要重新缩放的
多段线图元
中有一组
图元
对象。我创建了
Extents3d
对象来重新缩放对象,以避免逐个重新缩放对象,但它不起作用:

Document document = Application.DocumentManager.MdiActiveDocument;
Database database = document.Database;


using(Transaction transaction = database.TransactionManager.StartTransaction())
{
   BlockTable blockTable = transaction.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
   BlockTableRecord blockTableRecord = transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
   Polyline polyline = new Polyline();
   polyline.AddVertexAt(0, new Point2d(0.0, 0.0), 0, 0, 0);
   polyline.AddVertexAt(1, new Point2d(100.0, 100.0), 0, 0, 0);
   polyline.AddVertexAt(2, new Point2d(50.0, 500.0), 0, 0, 0);
   polyline.Closed = true;
   blockTableRecord.AppendEntity(polyline);
   transaction.AddNewlyCreatedDBObject(polyline, true);
   Extents3d boundary = polyline.GeometricExtents;
   boundary.TransformBy(Matrix3d.Scaling(1, Point3d.Origin));
   transaction.commit();
}

应将变换应用于多段线本身,而不是边界(表示几何图形空间,而不是实体)

关于沿一个方向缩放,问题在于变换上的原点/基点:如果设置原点,它将从0,0,0缩放,现在如果要“沿所有方向缩放”,请使用多段线中间的点。检查下面


另请注意,比例因子为1,您需要一个不同的值:>1将向上缩放,重新阅读您的问题,如果要缩放由多边形区域分隔的实体,则首先需要选择它们,即比例。您的代码绝对不会这样做(我的建议也是如此)

要选择,请使用下面复制的代码:请参阅专用编辑器。选择****方法

选择后,可以应用变换。请注意原点/基点和比例因子

[CommandMethod("SEL")]
public void MySelection()
{
    Document doc = Autodesk.AutoCAD
        .ApplicationServices.Application
        .DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;

    Point3d p1 = new Point3d(10.0, 10.0, 0.0);
    Point3d p2 = new Point3d(10.0, 11.0, 0.0);
    Point3d p3 = new Point3d(11.0, 11.0, 0.0);
    Point3d p4 = new Point3d(11.0, 10.0, 0.0);

    Point3dCollection pntCol =
                      new Point3dCollection();
    pntCol.Add(p1);
    pntCol.Add(p2);
    pntCol.Add(p3);
    pntCol.Add(p4);

    int numOfEntsFound = 0;

    PromptSelectionResult pmtSelRes = null;

    TypedValue[] typedVal = new TypedValue[1];
    typedVal[0] = new TypedValue
                 ((int)DxfCode.Start, "Line");

    SelectionFilter selFilter =
              new SelectionFilter(typedVal);
    pmtSelRes = ed.SelectCrossingPolygon
                         (pntCol, selFilter);
    // May not find entities in the UCS area
    // between p1 and p3 if not PLAN view
    // pmtSelRes =
    //    ed.SelectCrossingWindow(p1, p3, selFilter);

    if (pmtSelRes.Status == PromptStatus.OK)
    {
        foreach (ObjectId objId in
            pmtSelRes.Value.GetObjectIds())
        {
            numOfEntsFound++;
        }
        ed.WriteMessage("Entities found " +
                    numOfEntsFound.ToString());
    }
    else
        ed.WriteMessage("\nDid not find entities");
}

你说“它不起作用”是什么意思?对象没有调整大小吗?是否有异常、错误、无更改?我的意思是对象没有调整大小。这非常有用,谢谢!只有一件事,边界点是矩形的。任何给定的形状都有效吗?我也不理解评论中提到的内容:“如果不是平面图,可能无法在p1和p3之间的UCS区域中找到实体…”
[CommandMethod("SEL")]
public void MySelection()
{
    Document doc = Autodesk.AutoCAD
        .ApplicationServices.Application
        .DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;

    Point3d p1 = new Point3d(10.0, 10.0, 0.0);
    Point3d p2 = new Point3d(10.0, 11.0, 0.0);
    Point3d p3 = new Point3d(11.0, 11.0, 0.0);
    Point3d p4 = new Point3d(11.0, 10.0, 0.0);

    Point3dCollection pntCol =
                      new Point3dCollection();
    pntCol.Add(p1);
    pntCol.Add(p2);
    pntCol.Add(p3);
    pntCol.Add(p4);

    int numOfEntsFound = 0;

    PromptSelectionResult pmtSelRes = null;

    TypedValue[] typedVal = new TypedValue[1];
    typedVal[0] = new TypedValue
                 ((int)DxfCode.Start, "Line");

    SelectionFilter selFilter =
              new SelectionFilter(typedVal);
    pmtSelRes = ed.SelectCrossingPolygon
                         (pntCol, selFilter);
    // May not find entities in the UCS area
    // between p1 and p3 if not PLAN view
    // pmtSelRes =
    //    ed.SelectCrossingWindow(p1, p3, selFilter);

    if (pmtSelRes.Status == PromptStatus.OK)
    {
        foreach (ObjectId objId in
            pmtSelRes.Value.GetObjectIds())
        {
            numOfEntsFound++;
        }
        ed.WriteMessage("Entities found " +
                    numOfEntsFound.ToString());
    }
    else
        ed.WriteMessage("\nDid not find entities");
}