Author Topic: Retaining User Input When Repeating A Command  (Read 1206 times)

0 Members and 1 Guest are viewing this topic.

Cuddles

  • Guest
Retaining User Input When Repeating A Command
« on: December 21, 2014, 08:17:03 PM »
Hello All,

I'm just curious as to how i may have a program store a users inputs for when repeating a command.
Example: A user invokes a command and enters at the command line say length and width, and then draws and exits the command. Upon re-invoking the command, the previous inputs are retained and user draws the object again if they desire or these values may be overwritten with new values.

Could someone explain to me how this can be done, or provide links to such sources explaining this topic.

Thanks,

Cuddles

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Retaining User Input When Repeating A Command
« Reply #1 on: December 22, 2014, 03:41:55 AM »
I'll assume the 'command' is one that you are writing.
Something to play with.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun _store-vars (quotedVarList varName value /)
  3.    (if (cdr (assoc VarName (eval quotedVarList)))
  4.       (set quotedVarList
  5.            (subst (cons varName value)
  6.                   (assoc varName (eval quotedVarList))
  7.                   (eval quotedVarList)
  8.            )
  9.       )
  10.       ;; else
  11.       (set quotedVarList (cons (cons varName value) (eval quotedVarList)))
  12.    )
  13. )
  14. ;;------------------------------
  15.  
  16. (defun _retrieve-vars (quotedVarList varName default /)
  17.    (cond
  18.       ((cdr (assoc VarName (eval quotedVarList))))
  19.       (default)
  20.    )
  21. )
  22.  

Code - Auto/Visual Lisp: [Select]
  1. (defun _get-int-default (promptmsg quotedVarList varName default / returnvalue)
  2.    (setq default   (retrieve-vars quotedVarList varName default)
  3.          promptmsg (strcat "\n"
  4.                            (cond (promptmsg)
  5.                                  ("Specify Integer Value")
  6.                            )
  7.                            (if (and default (= (type default) 'int))
  8.  
  9.                               (strcat " << " (itoa default) " >>")
  10.  
  11.                               ""
  12.                            )
  13.                            ": "
  14.                    )
  15.    )
  16.           (setq returnvalue (vl-catch-all-apply 'getint (list promptmsg)))
  17.        )
  18.       ;; ESC was pressed.
  19.       (setq returnvalue nil
  20.             default nil
  21.       )
  22.    )
  23.    (if returnvalue
  24.       returnvalue
  25.       default
  26.    )
  27. )
  28.  

Code - Auto/Visual Lisp: [Select]
  1. (defun _get-string-default (promptmsg quotedVarList varName default / returnvalue)
  2.    (setq default   (retrieve-vars quotedVarList varName default)
  3.          promptmsg (strcat "\n"
  4.                            (cond (promptmsg)
  5.                                  ("Specify String Value")
  6.                            )
  7.                    )
  8.    )
  9.    (if (and default (= (type default) 'str) (/= default ""))
  10.       (progn (setq promptmsg (strcat "\n" promptmsg " << " default " >>: "))
  11.              (if (vl-catch-all-error-p
  12.                     (setq returnvalue
  13.                             (vl-catch-all-apply
  14.                                'getstring
  15.                                (list allowspaces promptmsg)
  16.                             )
  17.                     )
  18.                  )
  19.                 ;; ESC was pressed.
  20.                 (setq returnvalue nil
  21.                       default nil
  22.                 )
  23.              )
  24.              (setq returnvalue
  25.                      (if (= returnvalue "")
  26.                         default
  27.                         returnvalue
  28.                      )
  29.              )
  30.       )
  31.       ;; Else no default,
  32.       (setq returnvalue nil)
  33.    )
  34.    returnvalue
  35. )
  36.  

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (_store-vars '**Test1Vars 'v1 600)
  3. (_store-vars '**Test1Vars 'v2 200)
  4. (_store-vars '**Test1Vars 'vs1 "alpha")
  5. (_store-vars '**Test1Vars 'vs1 "bravo")
  6.  
  7. (retrieve-vars '**Test1Vars 'vs1 "Charlies")
  8. (retrieve-vars '**Test1Vars 'vs2 "Charlies")
  9.  
  10.  
  11. (foreach var (eval '**Test1Vars)
  12.    (print var)
  13. )
  14.  

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  
  3. (if (setq Var-1 (_get-int-default "Input Integer value" '**Test1Vars 'Var-1 100))
  4.    (_store-vars '**Test1Vars 'Var-1 Var-1)
  5.    (alert "ESC pressed")
  6. )
  7. (alert (strcat "Var-1 : " (itoa var-1)))
  8.  
  9.  
  10. (if (setq Var-2 (_get-string-default "Input String value" '**Test1Vars 'Var-2 "alpha"))
  11.    (_store-vars '**Test1Vars 'Var-2 Var-2)
  12.    (alert "ESC pressed")
  13. )
  14. (alert (strcat "Var-2 : " var-2))
  15.  
  16.  
  17. (foreach var (eval '**Test1Vars)
  18.    (print var)
  19. )
  20.  
  21.  
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.