Editor的路径:
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
PickFirst选择集
Editor.SelectImplied() —获取命令执行前所选择的选择集(PickFirst选择集)
使用PickFirst选择集系统变量PICKFIRST必须设置为1
使用PickFirst选择集的命令必须定义好UsePickSet命令标志
Editor.SetImpliedSelection() —设置PickFirst选择集
一般选择集
Editor.GetSelection() —提示用户从屏幕拾取对象
Editor.SelectAll() —选择当前空间内所有未锁定及未冻结的对象
Editor.SelecCrossingPolygon() —选择由给定点定义的多边形内的所有对象以及与多边形相交的对象
边界多边形不能自交
Editor.SelectWindow() —选择完全框入由两个点定义的矩形内的所有对象
Editor.SelectCrossingWindow() —选择由两个点定义的窗口内的对象以及与窗口相交的对象
Editor.SelectWindowPolygon() —选择完全框入由点定义的多边形内的对象
1、GetSelection: 该方法用于获取当前选择集中的所有对象。返回一个实体对象数组。
2、SelectAll: 该方法用于将所有的实体对象添加到选择集中。
3、SelectFence: 该方法用于通过指定的多边形范围选择实体对象。需要传入包含多边形顶点坐标的数组。
4、SelectWindowPolygon: 该方法用于通过指定的多边形范围选择实体对象。需要传入包含多边形顶点坐标的数组。
5、SelectWindow: 该方法用于通过指定的矩形范围选择实体对象。需要传入矩形左上角和右下角的坐标。
1. GetSelection()
这是一个用于获取选择集的方法,可以通过指定的条件来获取符合条件的对象。例如,可以使用坐标范围、图层名称、对象类型等来筛选对象,并返回符合条件的对象集合。
PromptSelectionResult GetSelection(
SelectionFilter filter = null,
string messageForUser = "",
bool allowDuplicates = false)
filter
:可选参数,用于设置对象类型过滤器,限制用户只能选择符合特定类型的对象。messageForUser
:可选字符串参数,向用户显示的提示信息,告诉用户应该选择什么类型的对象或提供其他指导。allowDuplicates
:一个布尔值,指示是否允许用户选择已选中的对象(即允许多次选择同一个对象)。
GetSelection`方法用于提示用户从绘图界面中选择对象,并返回一个`PromptSelectionResult`对象。这个结果包含了用户选择的对象所构成的选择集。可以选择性地传递一个`SelectionFilter`参数来限制用户只能选择特定类型的对象,也可以设置消息提示和是否允许重复选择同一对象。
使用示例:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
// 获取当前编辑器
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
// 设置筛选器只选择线型对象
SelectionFilter lineFilter = new SelectionFilter(new TypedValue[] { new TypedValue((int)DxfCode.ObjectType, "AcDbLine") });
// 提示用户选择线段,并显示自定义消息
PromptSelectionResult result = ed.GetSelection(messageForUser: "请选择线段", filter: lineFilter);
if (result.Status == PromptStatus.OK)
{
SelectionSet selectionSet = result.Value;
// 处理所选的对象...
}
2. SelectAll()
SelectAll: 该方法用于选择所有的CAD对象,无需任何筛选条件。它会将场景中的所有对象添加到当前的选择集中,以便后续操作。
所有未锁定及未冻结的对象,并将这些对象放入一个新的`SelectionSet`中。此方法通常用于一次性选取全部可见且可选的对象,而不是通过用户交互方式选取。
3.SelectFence()
SelectFence: 这是一个根据多边形围栏选择对象的方法。可以通过传递一个多边形的坐标点集合来选择围栏范围内的对象。
PromptSelectionResult SelectFence(
Point3d[] fencePoints,
SelectionFilter filter = null,
bool crossing = true,
bool wholeObjects = true)
fencePoints
:一组三维点数组,这些点用来定义围栏(多条直线相连形成的边界),用户可以通过鼠标绘制。filter
:同上,对象类型过滤器。crossing
:布尔值,如果为true
,则选择与围栏相交的对象;否则仅选择完全位于围栏内的对象。wholeObjects
:布尔值,如果为true
,则要求整个对象必须在围栏内或者与围栏交叉才被选中,而不是部分在围栏内即可。
`SelectFence`方法让用户通过绘制一条或多条线段(围栏)来选择与围栏相交或完全位于围栏内的对象。可以根据需要传递筛选器和指定是否包括交叉的对象以及整个对象是否必须被围栏完全包含。
使用示例:
Point3dCollection fencePath = new Point3dCollection();
// 假设我们已经有了两个点来定义围栏
fencePath.Add(new Point3d(0, 0, 0));
fencePath.Add(new Point3d(10, 10, 0));
PromptSelectionResult fenceResult = ed.SelectFence(fencePath.ToArray(), filter: null, crossing: true, wholeObjects: false);
if (fenceResult.Status == PromptStatus.OK)
{
SelectionSet fenceSelection = fenceResult.Value;
// 处理所选的对象...
}
4. SelectWindowPolygon()
SelectWindowPolygon: 类似于SelectFence,但选择窗口不是完全填充的。可以通过传递一个多边形的坐标点集合来选择多边形内的对象。
SelectWindowPolygon(Point3dCollection polygon, SelectionFilter filter)
`参数说明
-
Point3dCollection polygon
:表示用于定义多边形区域的点集合。这些点将定义一个多边形,用于限定选择区域。 -
SelectionFilter filter
:可能是用于指定对选择进行进一步筛选的条件或过滤器。这个过滤器可以用来指定所选对象的类型或其他属性。
使用示例:
// 创建并填充一个表示外部多段线边界坐标的点集合
Point3dCollection outerPoints = new Point3dCollection();
for (int i = 0; i < polyline.NumberOfVertices; i++)
{
Point3d point = polyline.GetPoint3dAt(i);
outerPoints.Add(point);
}
// 创建一个窗口选择过滤器,用于选择位于外部多段线内的所有实体
SelectionFilter innerFilter = new SelectionFilter(new TypedValue[] {
new TypedValue((int)DxfCode.Start, "LWPOLYLINE"),
new TypedValue((int)DxfCode.LayerName, "JMD")
});
// 使用多边形窗口选择方式让用户选择位于外部多段线内的实体
PromptSelectionResult innerSelRes = ed.SelectWindowPolygon(outerPoints, innerFilter);
5. SelectWindow()
SelectWindow: 这是一个根据矩形窗口选择对象的方法。可以通过传递一个矩形的左下角和右上角坐标来选择指定范围内的对象。
PromptSelectionResult SelectWindow(
Point3d cornerPoint1,
Point3d cornerPoint2,
SelectionFilter filter = null,
bool crossing = true)
cornerPoint1
和cornerPoint2
:二维或三维空间中的两个点,它们确定了一个矩形选择窗口的对角线。- 其他参数同上。
使用示例:
Point3d point1 = new Point3d(0, 0, 0);
Point3d point2 = new Point3d(10, 10, 0);
PromptSelectionResult windowResult = ed.SelectWindow(point1, point2, filter: null, crossing: true);
if (windowResult.Status == PromptStatus.OK)
{
SelectionSet windowSelection = windowResult.Value;
// 处理所选的对象...
}
`SelectWindow`方法以两个点定义一个矩形窗口,在窗口范围内的对象将被选中,如果`crossing`参数为`true`,则与窗口边界相交的对象也会被选中。同样可以使用筛选器限制选择对象类型。
//感谢大家的点赞,收藏,转发,关注