简体   繁体   English

如何为折线内的一组实体应用变换?

[英]How to apply a transformation for a group of entities inside a polyline?

I have a group of entity objects inside a polyline entity that I want to rescale. 我在polyline entity中有一组entity对象,我想要重新缩放。 I have created Extents3d object to rescale the objects in order to avoid rescale objects one by one, but it doesn't work: 我创建了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();
}

Re-reading your question, if you want to scale entities delimited by the Polygon area, then you first need to select them, the scale. 重新阅读您的问题,如果要缩放由多边形区域分隔的实体,则首先需要选择它们,即比例。 You code is definitely not doing this (neither my suggestion). 你的代码绝对没有这样做(我的建议都没有)。

To select, use the code described here and copied below: see the special Editor.Select**** method. 要选择,请使用此处描述的代码并在下面复制:请参阅特殊的Editor.Select ****方法。

After you select, then you can apply the transform. 选择后,您可以应用转换。 Please observe the origin/base point and scale factor. 请注意原点/基点和比例因子。

[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");
}

You should apply the transform to the polyline itself, not the boundary (that represents a geometry space, not an entity). 您应该将变换应用于折线本身,而不是边界(表示几何空间,而不是实体)。

About scaling in one direction, the problem is the Origin/Base point on the transform: if you set the Origin, it will scale from 0,0,0, now if you want to 'scale in all directions', use a point at the middle of the polyline. 关于在一个方向上缩放,问题是变换上的原点/基点:如果设置原点,它将从0,0,0缩放,现在如果你想“在所有方向上缩放”,请使用点折线的中间。 Check below. 检查下面。

Also note your scale factor is 1, you need a different value: >1 will is scale up, <1 will scale down. 另请注意您的比例因子为1,您需要一个不同的值:> 1将按比例放大,<1将按比例缩小。

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;
   Point3d center = (new LineSegment3d(boundary.MinPoint, boundary.MaxPoint)).MidPoint;
   polyline.TransformBy(Matrix3d.Scaling(1, center));
   transaction.commit();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM