明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1630|回复: 1

[源码] 【函数】判断命令是否存在

[复制链接]
发表于 2015-6-7 21:07:05 | 显示全部楼层 |阅读模式
本帖最后由 叶曲冰寒 于 2015-6-7 21:33 编辑

    关于命令是否存在的问题之前在网上找了很多地方都没完全搞定。关于命令是否存在的判断结合众牛人的看法,和自己的总结写出来供各位看官瞅瞅。此函数能够判断CAD内置命令和用户定义的命令。
  1. ;;功  能:命令是否存在
  2. ;;参  数:命令字符串
  3. ;;返回值:存在为T,否则为nil
  4. (defun isCommandExist(commandstr / cAndCommandStr isexist myvalue)
  5.   (setq cAndCommandStr (strcat "c:" commandStr))
  6.   (if (equal (type (eval (read cAndCommandStr))) 'subr)
  7.     ;;说明是用lisp的defun定义的命令
  8.     (progn
  9.       (setq isExist T)
  10.       (print "命令存在!")
  11.     )
  12.     ;;不是lisp中defun定义的命令
  13.     (progn
  14.       (if
  15.         ;;if判断的条件
  16.         (not
  17.           ;;捕捉错误,错误存在为T,不存在为FALSE
  18.           (vl-catch-all-error-p
  19.             (setq myvalue
  20.               ;;执行语句,并且用vl-catch-all-apply捕捉错误
  21.               (vl-catch-all-apply '(lambda (x) (progn (command x) (setq lastCommand (getvar "LASTPROMPT")) (if (not (wcmatch lastCommand "*未知命令*")) (command "ESC")))) (list commandStr))
  22.             )
  23.           )
  24.         )
  25.         ;;if条件后的第一条语句
  26.         ;;如果执行出错就执行下面这句
  27.         (progn
  28.           (setq isExist nil)
  29.           (print "命令不存在!")
  30.         )
  31.         ;;if条件后的第二条语句
  32.         ;;如果执行出错,就捕捉错误,执行下面这句
  33.         (progn
  34.           (setq isExist T)
  35.           (print "命令存在!")
  36.         )
  37.       );;end if
  38.       ;;取消命令操作
  39.       (if isExist
  40.         (progn
  41.           (command)
  42.         )
  43.       );;end if
  44.     );;end progn
  45.   );;end if
  46.   
  47.   ;;输出值,命令存在时是T,否则是nil
  48.   isExist
  49. )



本帖子中包含更多资源

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

x
发表于 2015-6-8 08:15:48 | 显示全部楼层
本帖最后由 USER2128 于 2015-6-8 08:18 编辑

可以参考我的贴子:
判断是否为CAD命令的简写

可以判断出:
1、是否为CAD命令的简写;
2、是否为CAD系统内置命令;
3、是否为CAD系统内置函数;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-21 23:53 , Processed in 0.174914 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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