CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

获取选择优先选择集 (.NET)

2023-1-1 14:33| 发布者: admin| 查看: 1632| 评论: 0|来自: AutoCAD

PickFirst 选择集是在启动命令之前选择对象时创建的。为了获取 PickFirst 选择集的对象,必须存在几个条件,这些条件是:

  • PICKFIRST 系统变量必须设置为 1
  • UsePickSet必须使用应使用 PickFirst 选择集的命令定义命令标志
  • 调用该方法以获取 PickFirst 选择集SelectImplied

该方法用于清除当前的“选择优先”选择集。SetImpliedSelection

获取“选择优先”选择集

本示例显示 PickFirst 选择集中的对象数,然后要求用户选择其他对象。在请求用户选择对象之前,将使用该方法清除当前的 PickFirst 选择集。SetImpliedSelection

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
 
<CommandMethod("CheckForPickfirstSelection", CommandFlags.UsePickSet)> _
Public Sub CheckForPickfirstSelection()
    '' Get the current document
    Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor

    '' Get the PickFirst selection set
    Dim acSSPrompt As PromptSelectionResult
    acSSPrompt = acDocEd.SelectImplied()

    Dim acSSet As SelectionSet

    '' If the prompt status is OK, objects were selected before 
    '' the command was started
    If acSSPrompt.Status = PromptStatus.OK Then
        acSSet = acSSPrompt.Value

        Application.ShowAlertDialog("Number of objects in Pickfirst selection: " & _
                                    acSSet.Count.ToString())
    Else
        Application.ShowAlertDialog("Number of objects in Pickfirst selection: 0")
    End If

    '' Clear the PickFirst selection set
    Dim idarrayEmpty() As ObjectId
    acDocEd.SetImpliedSelection(idarrayEmpty)

    '' Request for objects to be selected in the drawing area
    acSSPrompt = acDocEd.GetSelection()

    '' If the prompt status is OK, objects were selected
    If acSSPrompt.Status = PromptStatus.OK Then
        acSSet = acSSPrompt.Value

        Application.ShowAlertDialog("Number of objects selected: " & _
                                    acSSet.Count.ToString())
    Else
        Application.ShowAlertDialog("Number of objects selected: 0")
    End If
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
 
[CommandMethod("CheckForPickfirstSelection", CommandFlags.UsePickSet)]
public static void CheckForPickfirstSelection()
{
    // Get the current document
    Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;

    // Get the PickFirst selection set
    PromptSelectionResult acSSPrompt;
    acSSPrompt = acDocEd.SelectImplied();

    SelectionSet acSSet;

    // If the prompt status is OK, objects were selected before
    // the command was started
    if (acSSPrompt.Status == PromptStatus.OK)
    {
        acSSet = acSSPrompt.Value;

        Application.ShowAlertDialog("Number of objects in Pickfirst selection: " +
                                    acSSet.Count.ToString());
    }
    else
    {
        Application.ShowAlertDialog("Number of objects in Pickfirst selection: 0");
    }

    // Clear the PickFirst selection set
    ObjectId[] idarrayEmpty = new ObjectId[0];
    acDocEd.SetImpliedSelection(idarrayEmpty);

    // Request for objects to be selected in the drawing area
    acSSPrompt = acDocEd.GetSelection();

    // If the prompt status is OK, objects were selected
    if (acSSPrompt.Status == PromptStatus.OK)
    {
        acSSet = acSSPrompt.Value;

        Application.ShowAlertDialog("Number of objects selected: " +
                                    acSSet.Count.ToString());
    }
    else
    {
        Application.ShowAlertDialog("Number of objects selected: 0");
    }
}

VBA/ActiveX 代码参考

Sub CheckForPickfirstSelection()
    ' Get the Pickfirst selection set
    Dim acSSet As AcadSelectionSet
    Set acSSet = ThisDrawing.PickfirstSelectionSet
 
    ' Display the number of selected objects
    MsgBox "Number of objects in Pickfirst selection set: " & acSSet.Count
 
    ' Create a new selection set
    Dim acSSetUser As AcadSelectionSet
    Set acSSetUser = ThisDrawing.SelectionSets.Add("User")
 
    ' Select objects in the drawing
    acSSetUser.SelectOnScreen
 
    ' Display the number of selected objects
    MsgBox "Number of objects selected: " & acSSetUser.Count
    ' Remove the new named selection set
    acSSetUser.Delete
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 12:12

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部