代码拉取完成,页面将自动刷新
namespace TestShared;
public class TestExtents
{
[CommandMethod(nameof(Test_BlockExtents))]
public void Test_BlockExtents()
{
using var tr = new DBTrans();
var ent = Env.Editor.GetEntity("pick the entity");
if (ent.Status != PromptStatus.OK )
{
return;
}
var block = ent.ObjectId.GetObject<Entity>();
if (block != null && block.Bounds.HasValue)
{
var extent = block.GeometricExtents;
List<Point3d> pts = [
extent.MinPoint,
new Point3d(extent.MinPoint.X,extent.MaxPoint.Y,0),
extent.MaxPoint,
new Point3d(extent.MaxPoint.X,extent.MinPoint.Y,0),
];
tr.CurrentSpace.AddEntity(pts.CreatePolyline(action: e => e.ColorIndex = 1));
if (block is BlockReference block1)
{
var extents = block1.GeometryExtentsBestFit();
List<Point3d> pts1 =
[
extents.MinPoint,
new Point3d(extents.MinPoint.X, extents.MaxPoint.Y, 0),
extents.MaxPoint,
new Point3d(extents.MaxPoint.X, extents.MinPoint.Y, 0),
];
tr.CurrentSpace.AddEntity(pts.CreatePolyline(action: e => e.ColorIndex = 2));
var extents2 = block1.GetBoundingBoxEx();
tr.CurrentSpace.AddEntity(pts.CreatePolyline(action: e => e.ColorIndex = 3));
// 此处是计算块定义的包围盒,不是块参照的,所以一般情况下不需要使用。
var ext = new Extents3d();
ext.AddBlockExtents(block1.BlockTableRecord.GetObject<BlockTableRecord>());
tr.CurrentSpace.AddEntity(ext.CreatePolyline(action: e => e.ColorIndex = 4));
}
}
}
[CommandMethod(nameof(Test_entextents))]
public void Test_entextents()
{
using var tr = new DBTrans();
var a = Env.Editor.GetSelection().Value.
GetEntities<Entity>(OpenMode.ForWrite);
foreach (var e in a)
{
var b = e.Bounds.HasValue; //获取是否有包围盒
var name = e.ObjectId.ObjectClass.DxfName;
Env.Print($"{name}是否有包围盒-" + b);
if (b)
{
tr.CurrentSpace.AddEntity(e.Bounds!.Value.CreatePolyline(action: e =>
{
e.ColorIndex = 4;
e.Closed = true;
}));
var ext = e.GetBoundingBoxEx();
if (ext.HasValue)
{
tr.CurrentSpace.AddEntity(
ext.Value.Extents3d.CreatePolyline(action: e =>
{
e.ColorIndex = 5;
e.Closed = true;
}));
}
if (e is Curve spline)
{
var ge = spline.GetGeCurve();
var box = ge.BoundBlock;
List<Point3d> lst =
[
box.BasePoint,
box.BasePoint + box.Direction1,
box.BasePoint + box.Direction2,
box.BasePoint + box.Direction3,
];
tr.CurrentSpace.AddEntity(lst.CreatePolyline(action: e =>
{
e.ColorIndex = 6;
e.Closed = true;
}));
}
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。