如何对折线内的一组实体应用转换

本文关键字:一组 实体 转换 应用 折线 | 更新日期: 2023-09-27 18:14:05

我在polyline entity中有一组entity对象,我想重新缩放。我已经创建了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();
}

如何对折线内的一组实体应用转换

重读你的问题,如果你想缩放由多边形区域划分的实体,那么你首先需要选择它们,即缩放。你的代码绝对没有这样做(我也不建议)。

要选择,请使用这里描述的代码并在下面复制:参见特殊编辑器。选择* * * *方法。

选择之后,就可以应用转换了。请观察原点/基准点和比例因子。

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

您应该将转换应用于折线本身,而不是边界(表示几何空间,而不是实体)。

关于在一个方向上缩放,问题是变换上的原点/基点:如果你设置原点,它将从0,0,0缩放,现在如果你想"在所有方向上缩放",使用折线中间的一个点。检查下面。

还要注意你的比例因子是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();
}