CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 文档中心

command-s(AutoLISP)

2023-1-7 21:30| 发布者: admin| 查看: 283| 评论: 0|来自: AutoCAD

摘要: 执行 AutoCAD 命令和提供的输入

执行 AutoCAD 命令和提供的输入

支持的平台:视窗和 Mac OS

签名

(command-s [cmdname [arguments ...]])
目录名称

类型:字符串

要执行的命令的名称。

参数

类型:整数、实数、字符串或列表

要提供给正在执行的命令的命令输入。

命令函数的参数可以是字符串、实数、整数或点,正如所执行命令的提示序列所预期的那样。空字符串 (“”) 等效于按键盘上的 Enter 键。

返回值

类型:

nil在命令对提供的参数执行完毕时由函数返回。当函数无法成功完成时返回 Anis。*error*

言论

有关详细信息,请参阅本主题后面的部分。

例子

下面的示例演示如何执行 AutoCAD CIRCLE 命令并创建直径为 2.75 的圆。

Command: (command-s "._circle" "5,4" "_d" 2.75)
nil

下面的示例演示如何提示用户输入圆的中心点。

Command: (setq cPt (getpoint "\nSpecify center point: "))
(5.0 4.0 0.0)

Command: (command-s "._circle" cPt "_d" 2.75)
nil

以下是使用 command-s 函数提示用户输入的无效用法。

Command: (command-s "._circle" (getpoint "\nSpecify center point: ") "_d" 2.75)

与函数的区别Command

该函数是函数的变体,它对命令令牌内容有一些限制,但由于内部逻辑差异,它比命令更快,并且可以用作处理程序。command-scommand*error*

命令令牌是提供给函数的单个参数。这可以是字符串、实数、整数、点、实体名称、列表等。以下示例显示了 AutoCAD LINE 命令和三个命令标记:command-s

(command-s "._line" "0,0" "5,7" "")

“-s”后缀代表提供的命令令牌的“子例程”执行。在此形式中,AutoCAD 直接从 AutoLISP 调用,在不同于主文档命令处理器的临时命令处理器中处理提供的命令令牌,然后返回,从而终止临时命令处理器。正在执行的命令必须在同一函数中启动和完成。command-s

相比之下,该函数仍然是所提供命令令牌的“协程”执行,其中 AutoLISP 一次评估一个令牌,将结果发送到 AutoCAD,然后返回以允许 AutoCAD 处理该令牌。然后,AutoCAD 将回调 AutoLISP,AutoLISP 将恢复对正在进行的表达式的计算。在此逻辑流中,后续令牌表达式可以查询 AutoCAD 以获取先前令牌处理的结果并使用它。command

总之,命令令牌处理的“协程”样式在功能上更强大,但在运行时可以使用的时间有限。命令令牌处理的“子例程”样式可以在更广泛的上下文中使用,但会提前处理所有命令令牌,并且实际执行是非交互式的。对于同一组命令令牌,函数明显更快。command-s

已知注意事项

使用函数时,必须考虑以下几点:command-s

  • 在单个命令表达式中馈送的令牌流必须表示完整的命令及其输入。处理完所有命令令牌后,任何正在进行的命令都将被取消。以下内容对函数无效:command-s
    (command-s "._line")
    (command-s "2,2" "12.25,9" "")
  • All command tokens will be evaluated before they are handed over to AutoCAD for execution. In contrast, the function actually performs each command token evaluation and then feeds the result to AutoCAD, which processes it before the next command token is processed. command
  • No "Pause" command tokens may be used. Expressions that interact with the drawing area or Command Window may be used, but will all be processed before AutoCAD receives and processes any of them.

    The following is not valid with the function: command-s

    (command-s "._line" "0,0" PAUSE "")
Caution: Although the function is similar to the function, caution should be taken when using U or UNDO to roll back the system state if there is an AutoCAD command already in progress when the AutoLISP expression is entered. In that case, the results of running UNDO may cause the command in progress to fail or even crash AutoCAD. command-scommand

*error* Handler

If your *error* handler uses the function, consider updating the way you define your custom handlers using the following methods: command*error*

  • Substitute command-s for command in *error* handler

    For typical handler cases where the previous state of the program needs to be restored and a few batch commands are executed, you can substitute for . The handler is called from the same context as it always has been. *error* (command-s <...>)(command <...>)*error*

    The following demonstrates a based handler using the function: *error*command-s

    (defun my_err(s)
      (prompt "\nERROR: mycmd failed or was cancelled")
      (setvar "clayer" old_clayer)
      (command-s "._undo" "_e")
      (setq *error* mv_oer)
    )
    
    (defun c:mycmd ()
      (setq old_err *error*
            *error* my_err
            old_clayer (getvar "clayer")
      )
    
      (setq insPt (getpoint "\nSpecify text insertion: "))
    
      (if (/= insPt nil)
        (progn
          (command-s "._undo" "_be")
          (command-s "._-layer" "_m" "Text" "_C" "3" "" "")
          (command-s "._-text" insPt "" "0" "Sample Text")
          (command-s "._undo" "_e")
        )
      )
    
      (setvar "clayer" old_clayer)
      (setq *error* mv_oer)
     (princ)
    )
  • 保留在*错误*处理程序中使用命令函数

    如果使用函数是不可行的选项,则仍然可以使用该函数,但代价是无法访问在处理时通常在 AutoLISP 调用堆栈上的任何本地符号。command-scommand*error*

    以下是继续在处理程序中使用函数所需的概述。command*error*

    • 使用自定义处理程序覆盖符号时,调用函数以通知 AutoLISP 错误处理将用于后续函数。*error**error**push-error-using-command*command
      注意:每当 AutoLISP 表达式求值开始时,AutoLISP 引擎都会假定该函数不允许在处理程序中使用。command*error*
    • 如果处理程序引用在 AutoLISP 程序失败或被取消时 AutoLISP 堆栈上的本地符号,则必须删除这些引用,或使引用的符号成为全局符号。*error*

      AutoLISP 调用堆栈上的所有本地符号都将被推出范围之外,因为 AutoLISP 计算器在进入处理程序之前被重置。*error*

    现在该函数可以在处理程序中使用。command*error*

    但是,如果您的程序实际上在其操作过程中推送和弹出错误处理程序,或者可以在调用其他未知的 AutoLISP 逻辑时调用 AutoLISP 逻辑,则可能需要执行更多步骤。

    • 恢复旧的错误处理程序时,还要调用函数以反转对理论函数的任何调用的效果。*pop-error-mode**push-error-using-command**push-error-using-stack*
    • 如果您的逻辑具有该处理程序的嵌套推送和弹出,并且 anhandler 已设置为通过调用来使用命令函数,而嵌套处理程序不会使用它,则可以通过在设置为当前处理程序的同一点调用来提供对 AutoLISP 堆栈上本地定义的符号的访问。如果这样做,您还必须在恢复旧处理程序后调用。*error**error**push-error-using-command**push-error-using-stack**error**pop-error-mode**error*

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-19 14:01

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部