
Commands and @R_419_6843@liSP® functions can be defined with the @R_419_6843@CAD .NET API through the use of two attributes: CommandMethod and Lispfunction. You place one of the two attributes before the method that should be called when the command or @R_419_6843@liSP function is executed in @R_419_6843@CAD.
可以通过@R_419_6843@CAD .NET API编程接口的两个属性来定义命令和@R_419_6843@liSP函数,这两个属性是:CommandMethod和Lispfunction。 只需将这两个属性之一放在@R_419_6843@CAD命令或@R_419_6843@liSP函数要调用的方法前即可。
Methods used for commands should not be defined with arguments. However,a method used to define an @R_419_6843@liSP function should be defined with a single argument of the ResultBuffer object type.
用来定义命令的方法不能定义参数,相反,用来定义@R_419_6843@liSP函数的方法必须定义一个ResultBuffer类型的参数。
topics in this section本节主题
· Command Definition 定义命令
· AutoLISP Function Definition 定义@R_419_6843@liSP函数
1、Command DeFinition定义命令
When defining a command,you use the CommandMethod attribute. The CommandMethod attribute expects a string value to use as the global name of the command that is being defined. Along with a global command name,the CommandMethod attribute can accept the following values:
定义命令使用CommandMethod属性。CommandMethod属性需要一个字符串值作为要定义的命令的全局名字。除了全局命令名,CommandMethod属性还可以接受下列参数值:
· Command Flags命令标志 - defines the behavior of the command 定义命令的行为;Group name组名 - Command group name 命令编组名称;Local name本地名 - Local command name,usually language specific 指定语言的本地命令名称;Help topic name帮助主题名 - Help topic name that should be displayed when F1 is pressed 按下F1键是将要显示的帮助主题名;Context Menu Type Flags上下文菜单类型标志 - defines the context menu behavior when the command is active定义命令处于活动状态时的上下文菜单行为;Help file name帮助文件名 - Help file that contains the help topic that should be displayed when the command is active and F1 is pressed帮助文件,含有命令活动状态下按下F1时要显示的帮助主题;
The following table Lists the available flags that can be used to define the behavior of a command.
下表列出了定义命令行为用到的标志:
| Enum Value 枚举值 | Description 描述 |
| ActionMacro | Command can be recorded as an action with the Action Recorder. 可以用动作录制器录制命令动作; |
| DocReadLock | document will be read locked when command is invoked. 命令执行时将被只读锁定; |
| Interruptible | The command may be interrupted when prompting for user input. 提示用户输入时可以中断命令; |
| Modal | Command cannot be invoked while another command is active. 别的命令运行时不能运行此命令; | NoActionRecording | Command cannot be recorded as action with the Action Recorder. 不能用动作录制器录制命令动作; |
| NoBlockEditor | Command cannot be used from the Block Editor. 不能从块编辑器使用该命令; |
| NoHistory | Command is not added to the repeat-last-command history List. 不能将命令添加到重复上一个命令历史列表; |
| nopaperSpace | Command cannot be used from Paper space. 不能从图纸空间使用该命令; |
| NoTileMode | Command cannot be used when TILEMODE is set to 1. 当TILEMODE置1时不能使用该命令; |
| NoUndoMarker | Command does not support undo markers. This is intended for commands that do not modify the database,and therefore should not show up in the undo file. 命令不支持撤销标记。用于不修改数据库因而也就无需出现在撤销记录中的那些命令; |
| Redraw | When the pickfirst set or grip set are retrIEved,they are not cleared. 不清空取回的先选择后执行设置及对象捕捉设置; |
| Session | Command is executed in the context of the application rather than the current document context. 命令运行于应用程序上下文,而不是当前图形文档上下文; |
| transparent | Command can be used while another command is active. 别的命令运行时可以运行此命令; |
| Undefined | Command can only be used via its Global name. 只能通过全局名使用命令; |
| UsePickSet | When the pickfirst set is retrIEved,it is cleared. 清空取回的先选择后执行设置; |
Syntax to define a Command 定义命令的语法
The following demonstrates the creation of a CommandMethod attribute that defines a command named CheckForPickfirstSelection. The attribute also uses the command flag UsePickSet to indicate that the command is allowed to use the objects that are selected before the command is started.
下面演示使用CommandMethod属性创建一个名为CheckForPickfirstSelection命令,该属性还用UsePickSet命令标志,表示允许该命令使用命令启动前已经选择的对象。
VB.NET
<CommandMethod("CheckForPickfirstSelection",CommandFlags.UsePickSet)> _
Public Sub CheckForPickfirstSelection()
. . .
End Sub
C#
[CommandMethod("CheckForPickfirstSelection",CommandFlags.UsePickSet)]
public static voID CheckForPickfirstSelection()
{
. . .
}
You can specify the use of more than one flag by using the + operator in VB.NET and the & operator in C#.
用VB.NET里的+ *** 作符和C#里的& *** 作符,可以指定用多个命令标志。
CommandFlags.NoBlockEditor)> _
Public Sub CheckForPickfirstSelection()
. . .
End Sub
CommandFlags.NoBlockEditor)]
public static voID CheckForPickfirstSelection()
{
. . .
}
2、@R_419_6843@liSP Function DeFinition 定义@R_419_6843@liSP函数When defining an @R_419_6843@liSP function,you use the Lispfunction attribute. The Lispfunction attribute expects a string value to use as the global name of the @R_419_6843@liSP function that is being defined. Along with a global function name,the Lispfunction structure can accept the following values:
定义@R_419_6843@liSP函数用Lispfunction属性。Lispfunction属性需要一个字符串值作为要定义的@R_419_6843@liSP函数的全局名字。除了全局函数名,Lispfunction结构还可接受下列值:
· - Local function name,usually language specific 指定语言的本地函数名; - Help topic name that should be associated with the @R_419_6843@liSP function 与@R_419_6843@liSP函数关联的帮助主题名称;
Syntax to define an @R_419_6843@liSP Function 定义@R_419_6843@liSP函数的语法The following demonstrates the creation of a Lispfunction attribute that defines an @R_419_6843@liSP function named InsertDynamicBlock.
下面演示用Lispfunction属性创建了一个名为InsertDynamicBlock的@R_419_6843@liSP函数。
VB.NET
<Lispfunction("InsertDynamicBlock")> _
Public Sub InsertDynamicBlock(ByVal rbargs As ResultBuffer)
. . .
End Sub
C#
[Lispfunction("InsertDynamicBlock ")]
public static voID InsertDynamicBlock (ResultBuffer rbargs)
{
. . .
}
RetrIEve Values Passed into an @R_419_6843@liSP Function 检索传入@R_419_6843@liSP函数的值
Use a Foreach loop to step through the values returned in the ResultBuffer by the @R_419_6843@liSP function. A ResultBuffer is a collection of TypedValue objects. The TypeCode property of a TypedValue object can be used to determine the value type for each value passed into the @R_419_6843@liSP function. The Value property is used to return the value of the TypedValue object.
使用Foreach循环遍历@R_419_6843@liSP函数返回的ResultBuffer中的值。ResultBuffer是TypedValue(值类型)对象的集合。TypedValue对象的TypeCode属性用来确定传入@R_419_6843@liSP函数的每个值的类型,Value属性则返回TypedValue对象的值。
To define an @R_419_6843@liSP Function 定义一个@R_419_6843@liSP函数This example code defines an @R_419_6843@liSP function named displayFullname. While the method defined in the .NET project accepts a single value,the @R_419_6843@liSP function expects two string values to produce the correct output.
本例代码定义一个名为displayFullname的.NET项目里定义的方法接受一个值,而所定义的@R_419_6843@liSP函数需要两个字符串值来产生正确的输出结果。Load the .NET project into @R_419_6843@CAD and enter the following at the Command prompt:
将.NET项目加载到@R_419_6843@CAD,在命令提示行输入下列lisp指令:
(displayfullname "First" "Last")
The following is the output displayed after the @R_419_6843@liSP function is executed:
下面是@R_419_6843@liSP函数执行后显示的输出结果:
name: First Last
@L_502_17@VB.NET
imports @R_419_6843@desk.@R_419_6843@CAD.Runtime
imports @R_419_6843@desk.@R_419_6843@CAD.applicationservices
imports @R_419_6843@desk.@R_419_6843@CAD.DatabaseServices;
<Lispfunction("displayFullname")> _
Public Sub displayFullname(ByVal rbargs As ResultBuffer)
If Not rbargs = nothing Then
Dim strVal1 As String = "",strVal2 As String = ""
Dim nCnt As Integer = 0
For Each rb As TypedValue In rbargs
If (rb.TypeCode = @R_419_6843@desk.@R_419_6843@CAD.Runtime.lispDataType.Text) Then
Select Case nCnt
Case 0
strVal1 = rb.Value.ToString()
Case 1
strVal2 = rb.Value.ToString()
End Select
nCnt = nCnt + 1
End If
Next
Application.documentManager.MdiActivedocument.Editor. _
WriteMessage(vbLf & "name: " & strVal1 & " " & strVal2)
End If
End Sub
C#
using @R_419_6843@desk.@R_419_6843@CAD.Runtime;
using @R_419_6843@desk.@R_419_6843@CAD.applicationservices;
using @R_419_6843@desk.@R_419_6843@CAD.DatabaseServices;
[Lispfunction("displayFullname")]
public static voID displayFullname(ResultBuffer rbargs)
{
if (rbargs != null)
{
string strVal1 = "";
string strVal2 = "";
int nCnt = 0;
foreach (TypedValue rb in rbargs)
{
if (rb.TypeCode == (int)@R_419_6843@desk.@R_419_6843@CAD.Runtime.lispDataType.Text)
{
switch(nCnt)
{
case 0:
strVal1 = rb.Value.ToString();
break;
case 1:
strVal2 = rb.Value.ToString();
break;
}
nCnt = nCnt + 1;
}
}
Application.documentManager.MdiActivedocument.Editor.
WriteMessage("/nname: " + strVal1 + " " + strVal2);
}
}
总结以上是内存溢出为你收集整理的AutoCAD .NET API基础(六) 定义命令和AutoLISP函数全部内容,希望文章能够帮你解决AutoCAD .NET API基础(六) 定义命令和AutoLISP函数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)