MUSIC-DIE 发表于 2021-8-13 14:09:19

COMMAND COMMAND-S 自由切换!!!

BY:MUSIC-DIE 2021-08-13

在在高版本CAD中,使用command 总是弹出 建议使用 command-s

本插件提供在12版CAD之前和之后CAD共同使用一个command-switch   程序自动切换,和默认command用法一致!

例:(COMMAND-SWITCH "UNDO" "BE")

fas 可直接使用,

lsp需要使用海大师的修改工具修改后可用。

nyistjz 发表于 2021-8-13 16:24:43

(defun COMMAND-SWITCH (command-flow)
        (setq aaa 1122334455 aaa 0 xx 0)
        (if (> (read (substr (getvar "ACADVER") 1 2)) 18)
                (apply 'command-s command-flow)
                (apply 'command command-flow)
        )
)


(setq aaa 1122334455 aaa 0 xx 0)
这个设定有什么作用?

叮咚 发表于 2021-8-13 18:29:18

再给个范例:
(defun c:test()
(setq cmdx (if command-s command-s vl-cmdf))
(cmdx "line" (getpoint "\n第一点:")(getpoint "\n第2点:") "")
(cmdx "line" (getpoint "\n第一点:")(getpoint "\n第2点:")(getpoint "\n第3点:") "")
(princ)
)

vitalgg 发表于 2021-8-13 18:35:11

本帖最后由 vitalgg 于 2021-8-13 19:39 编辑

(setq @:cmd (if command-s command-s (if vl-cmdf vl-cmdf command)))
(@:cmd ....)

可变参数个数的功能在浩辰不能用。

弹出建议多是因为 自定义了 *error* ,后没有恢复 以及 没有 *push-error-using-command*
符号可以指向数值,字符串,也可以指向函数 ,指向表。


command 与 command-s比并不是一无是处。

自行翻译理解:

The command-s function is a variation of the command function which has some restrictions on command token content, but is both faster than command and can be used in *error* handlers due to internal logic differences.

A command token is a single argument provided to the command-s function. This could be a string, real, integer, point, entity name, list, and so on. The following example shows the AutoCAD LINE command and three command tokens:

(command-s "._line" "0,0" "5,7" "")
The "-s" suffix stands for "subroutine" execution of the supplied command tokens. In this form, AutoCAD is directly called from AutoLISP, processes the supplied command tokens in a temporary command processor distinct from the main document command processor, and then returns, thus terminating the temporary command processor. The command that is being executed must be started and completed in the same command-s function.

In contrast, the command function remains a "co-routine" execution of the supplied command tokens, where AutoLISP evaluates the tokens one at a time, sending the result to AutoCAD, and then returning to allow AutoCAD to process that token. AutoCAD then calls AutoLISP back, and AutoLISP resumes evaluation of the expression in progress. In this logic flow, subsequent token expressions can query AutoCAD for the results of previous token processing and use it.

In summary, the "co-routine" style of command token processing is more functionally powerful, but is limited in when it can be used when running. The "subroutine" style of command token processing can be used in a much wider range of contexts, but processes all command tokens in advance, and actual execution is non-interactive. For the same set of command tokens, command-s function is significantly faster.





叮咚 发表于 2021-8-13 14:49:57

要这么复杂吗?
把原来的command 改成下面的就行了
(if command-s command-s vl-cmdf)

MUSIC-DIE 发表于 2021-8-13 16:38:44

叮咚 发表于 2021-8-13 14:49
要这么复杂吗?
把原来的command 改成下面的就行了
(if command-s command-s vl-cmdf)

你试试看    不行的,command好像是不允许被重定义的

MUSIC-DIE 发表于 2021-8-13 16:39:11

nyistjz 发表于 2021-8-13 16:24
(defun COMMAND-SWITCH (command-flow)
        (setq aaa 1122334455 aaa 0 xx 0)
        (if (> (read (substr (getv ...

利用海大师的插件,,修改为支持无限参数

MUSIC-DIE 发表于 2021-8-13 16:40:32

叮咚 发表于 2021-8-13 14:49
要这么复杂吗?
把原来的command 改成下面的就行了
(if command-s command-s vl-cmdf)

http://bbs.mjtd.com/forum.php?mod=viewthread&tid=110075

叮咚 发表于 2021-8-13 17:49:58

MUSIC-DIE 发表于 2021-8-13 16:38
你试试看    不行的,command好像是不允许被重定义的

没有重定义,
((if command-s command-s vl-cmdf) "line" (getpoint "\n第一点:")(getpoint "\n第2点:") "")

MUSIC-DIE 发表于 2021-8-13 18:13:19

叮咚 发表于 2021-8-13 17:49
没有重定义,
((if command-s command-s vl-cmdf) "line" (getpoint "\n第一点:")(getpoint "\n第2点:") ...

这样也可以的,就是每次都这样写就可以了,我写的这个就不用if了,直接调用命令就行
页: [1] 2
查看完整版本: COMMAND COMMAND-S 自由切换!!!