CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

命令定义 (.NET)

2023-1-1 16:28| 发布者: admin| 查看: 1087| 评论: 0|来自: AutoCAD

定义命令时,使用属性。该属性需要一个字符串值用作正在定义的命令的全局名称。除了全局命令名称外,该属性还可以接受以下值:CommandMethodCommandMethodCommandMethod

  • 命令标志 - 定义命令的行为
  • 组名称 - 命令组名称
  • 本地名称 - 本地命令名称,通常特定于语言
  • 帮助主题名称 - 按 F1 时应显示的帮助主题名称
  • 上下文菜单类型标志 - 定义命令处于活动状态时的上下文菜单行为
  • 帮助文件名 - 包含命令处于活动状态且按 F1 时应显示的帮助主题的帮助文件

下表列出了可用于定义命令行为的可用标志。

枚举值 描述
动作宏 命令可以使用操作记录器记录为操作。
德芬 命令可以作为 LISP 函数调用,因此可以用来接收来自 LISP 的参数,并可以使用函数将值返回给 LISP。此标志只能由 Visual LISP 引擎设置。acedGetArgs()acedRetXxx()
文档独占锁 调用命令时,文档将被独占锁定。
文档读取锁定 调用命令时,文档将被读取锁定。
可中断 提示用户输入时,命令可能会中断。
模 态 当另一个命令处于活动状态时,无法调用命令。
无动作录制 命令不能记录为操作记录器的操作。
NoBlockEditor 不能从块编辑器中使用命令。
暂无历史 命令不会添加到重复上一个命令历史记录列表中。
NoInferConstraint 推断约束时不能使用命令。
否内部锁 文档无法在内部锁定。
无倍数 命令不支持以星号 (*) 作为命令宏的一部分作为前缀的多重行为。
NoNewStack 命令不会在堆栈上创建新项。
无代工 无法从 AutoCAD OEM 访问命令。
无纸空间 不能从图纸空间使用命令。
无视角 当 PERSPECTIVE 设置为 1 时,无法使用命令。
无平铺模式 当 TILEMODE 设置为 1 时,无法使用命令。
NoUndoMarker 命令不支持撤消标记。这适用于不修改数据库的命令,因此不应显示在撤消文件中。
重 绘 检索拾取第一个组或夹点组时,不会清除它们。
会期 命令在应用程序的上下文中执行,而不是在当前文档上下文中执行。
TempShowDynDimension 命令允许在选择图元时临时显示动态尺寸。
透明 当另一个命令处于活动状态时,可以使用命令。
定义 命令只能通过其全局名称使用。
使用选择集 检索第一个集时,将清除该集。

Instance and Static Command Methods

Command methods may be declared as either instance or static methods. Static command methods are declared with the static keyword in C#, or with the keyword in VB .NET. Instance command methods are public class members that are not declared with the static or keyword. SharedShared

For an instance command method, the method's enclosing type is instantiated separately for each open document. This means that each document gets a private copy of the command's instance data. Thus there is no danger of overwriting document-specific data when the user switches documents. If an instance method needs to share data globally, it can do so by declaring static or Shared member variables.

For a static command method, the managed wrapper runtime module does not need to instantiate the enclosing type. A single copy of the method's data is used, regardless of the document context. Static commands normally do not use per-document data and do not require special consideration for MDI mode.

Instance and static methods can be defined with command flags to accommodate special requirements. For example, an instance method may be declared with an attribute that sets the flag. This means that the command runs in the application execution context, but also maintains per-document data. An AutoCAD example of such a command is the PROPERTIES command. CommandFlags.Session

Likewise, a static method may be declared without the flag. This combination is useful for commands that run in the document context but do not need to maintain per-document data. CommandFlags.Session

Syntax to Define a Command

下面演示如何创建定义名为 CheckForPickfirstSelect 的命令的属性。该属性还使用命令标志来指示允许命令使用在启动命令之前选择的对象。CommandMethodUsePickSet

VB.NET

<CommandMethod("CheckForPickfirstSelection", CommandFlags.UsePickSet)> _
Public Sub CheckForPickfirstSelection()
 . . .
End Sub

C#

[CommandMethod("CheckForPickfirstSelection", CommandFlags.UsePickSet)]
public static void CheckForPickfirstSelection()
{
 . . .
}

您可以通过在 VB.NET 中使用 + 运算符来指定使用多个标志,|C# 中的运算符。

VB.NET

<CommandMethod("CheckForPickfirstSelection", CommandFlags.UsePickSet + _
                                             CommandFlags.NoBlockEditor)> _
Public Sub CheckForPickfirstSelection()
 . . .
End Sub

C#

[CommandMethod("CheckForPickfirstSelection", CommandFlags.UsePickSet |
                                             CommandFlags.NoBlockEditor)]
public static void CheckForPickfirstSelection()
{
 . . .
}

路过

雷人

握手

鲜花

鸡蛋

最新评论

AutoCAD Moldflow UG MoldWizard模具开发4合1

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

GMT+8, 2024-5-7 07:24

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部