TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: d2010 on December 10, 2021, 04:02:27 AM

Title: VLisp can detect unknown command, before execute?
Post by: d2010 on December 10, 2021, 04:02:27 AM
Now they either do not work or return "unknown command".
How to detect the command "leader" not exists inside this version of Acad?

Code: [Select]
(defun c:ll () (command "linetype" "load" "*" ""))
(defun c:le () (command "leader" pause pause pause "" "" "none"))
(defun c:ld () (command "leader" pause pause pause pause "F" "S" "" "" "none"))
(defun c:ldT () (command "leader" pause pause pause pause "F" "S" "" "" "none" "dtext" "j" "ml" pause "" ""))
(defun c:lt () (command "leader" pause pause pause "" "" "nONE" "dtext" "j" "ml" pause "" "" "dtext" "j" "l" ^C^C)
Title: Re: VLisp can detect unknown command, before execute?
Post by: Marc'Antonio Alessi on December 10, 2021, 09:16:04 AM
(getcname "leader") ?
Title: Re: VLisp can detect unknown command, before execute?
Post by: JohnK on December 10, 2021, 09:36:21 AM
On the interpreter level, There really isn't a way to know for sure but we can make a guess. They most likely have a lookup function like below.

Code - C++: [Select]
  1. lispval* builtin(lispval* a, char* func) {
  2.   if (strcmp("list", func) == 0) { return builtin_list(a); }
  3.   if (strcmp("car",  func) == 0) { return builtin_car(a); }
  4.   if (strcmp("cdr",  func) == 0) { return builtin_cdr(a); }
  5.   if (strcmp("eval", func) == 0) { return builtin_eval(a); }
  6.   if (strstr("+-/*", func)) { return builtin_op(a, func); }
  7.   ...
  8.   lispval_del(a);
  9.   return lispval_err("Unknown Function!");
  10. }
Title: Re: VLisp can detect unknown command, before execute?
Post by: d2010 on December 10, 2021, 09:47:02 AM
(getcname "leader") ?
Thank you,happym Best Regards..
Code: [Select]
AutoCAD menu utilities loaded.
Command: _RIBBON
Command: COMMANDLINE
Command: (getcname "leader")
"_LEADER"
Command: (getcname "leadeaar")
nil
Command: (getcname "trinitas.tv")
nil
Command: (getcname "line")
"_LINE"
Command: (getcname "Mline")
"_MLINE"
  :police:
Title: Re: VLisp can detect unknown command, before execute?
Post by: mhupp on December 10, 2021, 12:23:49 PM
This will only run a command if its loaded.

Code - Auto/Visual Lisp: [Select]
  1. (if (vl-symbol-value 'c:vp2m)
  2.   (C:VP2M)
  3. )

If you develop AutoLISP programs that can be used with a foreign-language version of AutoCAD, the standard AutoCAD commands and key words are automatically translated if you precede each command or key word with an underscore (_).

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ll () (command "_linetype" "load" "*" ""))
Title: Re: VLisp can detect unknown command, before execute?
Post by: baitang36 on December 16, 2021, 09:18:29 AM
(getcname "leader") ?
It's a good idea