明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3700|回复: 14

[函数] COMMAND COMMAND-S 自由切换!!!

[复制链接]
发表于 2021-8-13 14:09 | 显示全部楼层 |阅读模式
BY:MUSIC-DIE 2021-08-13

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

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

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

fas 可直接使用,

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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

评分

参与人数 1明经币 +1 收起 理由
xj6019 + 1 赞一个!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2021-8-13 16:24 | 显示全部楼层
(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)
这个设定有什么作用?
回复 支持 2 反对 0

使用道具 举报

发表于 2021-8-13 18:29 | 显示全部楼层
再给个范例:
  1. (defun c:test()
  2.   (setq cmdx (if command-s command-s vl-cmdf))
  3.   (cmdx "line" (getpoint "\n第一点:")(getpoint "\n第2点:") "")
  4.   (cmdx "line" (getpoint "\n第一点:")(getpoint "\n第2点:")  (getpoint "\n第3点:") "")
  5.   (princ)
  6. )
回复 支持 1 反对 0

使用道具 举报

发表于 2021-8-13 18:35 | 显示全部楼层
本帖最后由 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.





点评

command最大的好处就是可以直接调用cad命令,清晰明了简单。command-s再看有什么用?很多带点坐标的参数不能用,也就是必须放弃太多的Trim,FILLET,EXTEND命令。  发表于 2023-4-6 14:56
发表于 2021-8-13 14:49 | 显示全部楼层
要这么复杂吗?
把原来的command 改成下面的就行了
(if command-s command-s vl-cmdf)
 楼主| 发表于 2021-8-13 16:38 | 显示全部楼层
叮咚 发表于 2021-8-13 14:49
要这么复杂吗?
把原来的command 改成下面的就行了
(if command-s command-s vl-cmdf)

你试试看    不行的,command好像是不允许被重定义的
 楼主| 发表于 2021-8-13 16:39 | 显示全部楼层
nyistjz 发表于 2021-8-13 16:24
(defun COMMAND-SWITCH (command-flow)
        (setq aaa 1122334455 aaa 0 xx 0)
        (if (> (read (substr (getv ...

利用海大师的插件,,修改为支持无限参数
 楼主| 发表于 2021-8-13 16:40 | 显示全部楼层
叮咚 发表于 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 | 显示全部楼层
MUSIC-DIE 发表于 2021-8-13 16:38
你试试看    不行的,command好像是不允许被重定义的

没有重定义,
((if command-s command-s vl-cmdf) "line" (getpoint "\n第一点:")(getpoint "\n第2点:") "")
 楼主| 发表于 2021-8-13 18:13 | 显示全部楼层
叮咚 发表于 2021-8-13 17:49
没有重定义,
((if command-s command-s vl-cmdf) "line" (getpoint "\n第一点:")(getpoint "\n第2点:") ...

这样也可以的,就是每次都这样写就可以了,我写的这个就不用if  了,直接调用命令就行
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-3 18:47 , Processed in 0.261336 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表