Author Topic: Last Command executed  (Read 2046 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Last Command executed
« on: October 29, 2020, 06:23:50 AM »
Maybe it's very simple but...   With this function:
Code: [Select]
(defun C:DclUtils ( / Dcl_Id WhtNxt)
  (setq Dcl_Id (load_dialog "DclUtils.dcl"))
  (if (or (minusp Dcl_Id) (not (new_dialog "DclUtils" Dcl_Id))) (exit))
  (action_tile "accept"    "(done_dialog 0)")
  (action_tile "Program01" "(done_dialog 1)")
  (action_tile "Program02" "(done_dialog 2)")
  (setq WhtNxt (start_dialog))
  (cond
    ( (= 1 WhtNxt)    (C:Foo1) )
    ( (= 2 WhtNxt)    (C:Foo2) )
  )
  (unload_dialog Dcl_Id)
  (princ)
)

after the execution of the C:Foo1 or C:Foo2 commands if I press enter I re-launch the command C:DclUtils. Is there a way that pressing enter will launch the last command executed (C:Foo1 or C:Foo2) within C:DclUtils?

jtoverka

  • Newt
  • Posts: 127
Re: Last Command executed
« Reply #1 on: October 29, 2020, 06:55:20 AM »
Try this instead

Code - Auto/Visual Lisp: [Select]
  1.   ( (= 1 WhtNxt) (Command-s "Foo1") ) ; ( (= 1 WhtNxt) (C:Foo1) )
  2.   ( (= 2 WhtNxt) (Command-s "Foo2") ) ; ( (= 2 WhtNxt) (C:Foo2) )
  3. )
  4.  

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Last Command executed
« Reply #2 on: October 29, 2020, 04:56:00 PM »
Try this instead

Code - Auto/Visual Lisp: [Select]
  1.   ( (= 1 WhtNxt) (Command-s "Foo1") ) ; ( (= 1 WhtNxt) (C:Foo1) )
  2.   ( (= 2 WhtNxt) (Command-s "Foo2") ) ; ( (= 2 WhtNxt) (C:Foo2) )
  3. )
  4.  
Sorry but do not works:

Code: [Select]
Command: (defun C:Foo1 ( ) (print "Hallo "))
C:FOO1

Command: (c:Foo1)
"Hallo " "Hallo "

Command: (command "Foo1")
Unknown command "FOO1".  Press F1 for help.
nil

Command: (command-s "Foo1")
; error: Unknown (command-s) failure.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Last Command executed
« Reply #3 on: October 30, 2020, 08:52:28 AM »
I would suggest using sendcommand, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:dclutils ( / dch opt )
  2.     (if
  3.         (and
  4.             (< 0 (setq dch (load_dialog "dclutils.dcl")))
  5.             (new_dialog "dclutils" dch)
  6.         )
  7.         (progn
  8.             (foreach key '("Program01" "Program02")
  9.                 (action_tile key "(setq opt $key) (done_dialog 2)")
  10.             )
  11.             (cond
  12.                 (   (/= 2 (start_dialog)))
  13.                 (   (= "Program01" opt) (sendcommand "foo1\n"))
  14.                 (   (= "Program02" opt) (sendcommand "foo2\n"))
  15.             )
  16.             (unload_dialog dch)
  17.         )
  18.         (princ "\nUnable to load & open dialog.")
  19.     )
  20.     (princ)
  21. )
  22.  
  23. (defun sendcommand ( com )
  24.     (eval (list 'defun 'sendcommand '( com ) (list 'vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) 'com)))
  25.     (sendcommand com)
  26. )
  27.  

jtoverka

  • Newt
  • Posts: 127
Re: Last Command executed
« Reply #4 on: October 30, 2020, 09:09:35 AM »
Sorry but do not works:

I forgot to add

Code: [Select]
(vlax-add-cmd "FOO1" 'c:foo1)
(vlax-add-cmd "FOO2" 'c:foo2)

The command is invoked. However, I just tested it and that does not keep that as the last command unfortunately.

I would suggest using sendcommand

Fortunately, this command works well.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Last Command executed
« Reply #5 on: October 30, 2020, 10:26:06 AM »
I would suggest using sendcommand, e.g.: ….
GRANDE! It works :idea: In fact I thought that it would take a cunning. Thanks also to jtoverka.  :-)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Last Command executed
« Reply #6 on: October 30, 2020, 11:02:40 AM »
You're welcome  :-)