c# cad 选择集 GetSelection SelectAll SelectFence SelectWindowPolygon SelectWindow 参数使用

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)

`参数说明

  1. Point3dCollection polygon:表示用于定义多边形区域的点集合。这些点将定义一个多边形,用于限定选择区域。

  2. 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`,则与窗口边界相交的对象也会被选中。同样可以使用筛选器限制选择对象类型。

//感谢大家的点赞,收藏,转发,关注

  • 35
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在C#使用WPF窗口来开发AutoCAD插件,你需要使用AutoCAD .NET API和WPF技术。以下是基本步骤: 1. 在Visual Studio中创建一个新的Class Library项目。 2. 添加对AutoCAD .NET API的引用。这可以通过添加对acdbmgd.dll和acmgd.dll的引用来完成。 3. 在项目中添加一个新的WPF窗口或用户控件。 4. 在WPF窗口中添加必要的控件和事件处理程序。 5. 在AutoCAD中加载插件并在需要时显示WPF窗口。 以下是一个简单的示例,演示如何在AutoCAD使用WPF窗口: ```csharp using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using System.Windows.Controls; using System.Windows.Forms.Integration; namespace MyPlugin { public class MyCommands { [CommandMethod("MyCommand")] public void MyCommand() { // 获取当前文档和编辑器 Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; // 创建并显示WPF窗口 MyWpfWindow wpfWindow = new MyWpfWindow(); ElementHost.EnableModelessKeyboardInterop(wpfWindow); Autodesk.AutoCAD.ApplicationServices.Application.ShowModalWindow(wpfWindow); // 在控制台中显示选定的文本 PromptSelectionResult selRes = ed.GetSelection(); if (selRes.Status == PromptStatus.OK) { SelectionSet selSet = selRes.Value; foreach (SelectedObject selObj in selSet) { if (selObj.ObjectId.ObjectClass == RXClass.GetClass(typeof(DBText))) { DBText text = (DBText)selObj.ObjectId.GetObject(OpenMode.ForRead); ed.WriteMessage("Selected Text: " + text.TextString); } } } } } public class MyWpfWindow : UserControl { public MyWpfWindow() { // 添加WPF控件 TextBox textBox = new TextBox(); textBox.Text = "Hello, world!"; this.Content = textBox; } } } ``` 在这个示例中,我们在AutoCAD中创建了一个名为"MyCommand"的命令,当用户输入该命令时,会打开一个WPF窗口,并在控制台中显示选定的文本。WPF窗口中只包含一个文本框控件,其中包含"Hello, world!"文本。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值