gpt4 book ai didi

c# - 如何对折线内的一组实体应用转换?

转载 作者:太空宇宙 更新时间:2023-11-03 23:29:44 27 4
gpt4 key购买 nike

我在 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();
}

最佳答案

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

要选择,请使用代码 described here并复制如下:查看特殊的 Editor.Select**** 方法。

选择后,即可应用变换。请观察原点/基点和比例因子。

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

关于c# - 如何对折线内的一组实体应用转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32741832/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com