Results 1 to 3 of 3

Thread: Modification to a LISP routine

  1. #1
    I could stop if I wanted to
    Join Date
    Lake Charles, La.
    Login to Give a bone

    Default Modification to a LISP routine

    I have this routine that I would like to have modified and I know just the very basics of lisp programming.

    It's for monitoring specified sysvars while in a drawing session. What I'm wanting to do is take the routine below and set it up on a button to invoke the command. Which I am familiar with doing. Since you have to manually modify the routine as it is now for it to look at different sysvars, after clicking on the button, I would like it to ask me what variable I want monitored. Also, is there a way to set it up so that it can monitor more than one at a time? I would be interested in knowing how to go about setting it up for dialog box input. Not just at the command line.

    (defun C:ALERTME ()
    (setq VTFRXN (vlr-editor-reactor nil '((:VLR-sysVarChanged . VTF))))

    (defun VTF (CALL CALLBACK)
    (if (= (strcase (car CALLBACK)) (setq str "SAVETIME"))
    (alert (strcat str " has been changed "))

    I'm not necessarily asking for someone to modify it for me. Simply point me in the right direction or show me some examples you may have as I am trying to learn this as I go. Thanks in advance.

  2. #2
    Certifiable AUGI Addict
    Join Date
    Jo'burg SA
    Login to Give a bone

    Default Re: Modification to a LISP routine

    For creating the button, it would simply have a macro of ALERTME, because that's the new command created in this lisp file. All that you need make sure of is that the LSP file is loaded ... there's quite a few methods of ensuring this, eg.g. one of the following:
    • prefix the button's macro with (load "LISPFILENAME")
    • add the lisp file to the Appload - Startup Suite
    • add (load "LISPFILENAME") to the ACAD.LSP file
    • add (autoload "LISPFILENAME '("ALERTIME")) to the ACAD.LSP file
    I'd suggest the last option, as it will only load the file when the command is issued for the 1st time.

    Then to make the LSP catch other VARIABLES you have to store a list of SYSVAR names you'd like to check. Then change the the IF statement in the VTF function to check if the changed SYSVAR is in the list.

    I'd also suggest changing the c:ALERTIME function to 1st check if the reactor is already created, otherwise it will create a new reactor event every time you issue the command. Thus if you've issued the command 2 times, the alert box will pop-up twice for every change. If you've issued it 3 times, then the box will pop-up 3 times.

    So here's a suggested version:
    ;; Global Variable with list of SYSVARS to check, modify to check defaults
    (setq ALERTIME_LIST (list "SAVETIME"))
    (defun c:ALERTIME (/ varname rlst rcreate item ro)
      ;; Show user which sysvars will be checked
      (princ "\nCatching the following variables ")
      (prin1 ALERTIME_LIST)
      ;; Ask if any others should be checked
      (setq    varname
           "\nType the VARNAME if you want to add another to be checked:"
         ) ;_ end of getstring
      ) ;_ end of setq
      ;; Add to list only if specified, is a sysvar and not already added
      (if (and varname
           (/= "" varname)
           (getvar varname)
           (not (member (strcase varname) ALERTIME_LIST))
          ) ;_ end of and
        (setq ALERTIME_LIST (cons (strcase varname) ALERTIME_LIST))
      ) ;_ end of if
      ;; Check if reactor created
      (setq    rlst    (vlr-reactors)
        rcreate    T
      ) ;_ end of setq
      (foreach item    rlst
        (foreach ro    (cdr item)
          (if (= "ALERTIME" (vlr-data ro))
        (setq rcreate nil)
          ) ;_ end of if
        ) ;_ end of foreach
      ) ;_ end of foreach
      ;; Start the reactor only if it doesn't exist
      (if rcreate
          '((:vlr-sysVarChanged . VTF))
        ) ;_ end of vlr-editor-reactor
      ) ;_ end of if
    ) ;_ end of defun
    (defun VTF (CALL CALLBACK / str)
      (if (setq str (car (member (strcase (car CALLBACK)) ALERTIME_LIST)))
        (alert (strcat str " has been changed "))
      ) ;_ end of if
    ) ;_ end of defun

  3. #3
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    Login to Give a bone

    Default Re: Modification to a LISP routine

    I would suggest that you turn ON / OFF the reactor in the command function
    (defun C:AlertSysVars ( / ) ; Command that start/stop the reactor
      (if *VTFRXN*
          (vlr-remove *VTFRXN* ) ; Turn OFF
          (setq *VTFRXN* nil )
        (setq *VTFRXN* (vlr-editor-reactor nil '((:VLR-sysVarChanged . *VTF* ))) ) ; Turn ON
    and replace the if statement with a cond statement in the function that treat your sysvar callbak
    (defun *VTF* (CALL CALLBACK ) ; Function that is triggered by the reactor
    ; (alert (strcat (car CALLBACK ) " has been changed " ) ) ;; Uncommented shows all sysvars that changes
        ((= (car CALLBACK ) "SAVETIME" ) (alert (strcat (car CALLBACK ) " has been changed " )) )
        ((= (car CALLBACK ) "OSMODE"   ) (alert (strcat (car CALLBACK ) " has been changed " )) )
        ((= (car CALLBACK ) "BLIPMODE" ) (alert (strcat (car CALLBACK ) " has been changed " )) )
        ((= (car CALLBACK ) "LTSCALE " ) (alert (strcat (car CALLBACK ) " has been changed " )) )
    ;   ((= (car CALLBACK ) "MySysVar" ) (alert (strcat (car CALLBACK ) " has been changed " )) ) ; Add what you want
        (T nil )
    You can read more about reactors and how to load functions in the Sticky: Anatomy of an AUTOLISP file thread

    : ) Happy Computing !


Similar Threads

  1. select result lisp modification
    By chad.beussink in forum AutoLISP
    Replies: 10
    Last Post: 2023-10-24, 09:55 AM
  2. Text Modification Routine Needed
    By Mitch Mermel in forum AutoLISP
    Replies: 1
    Last Post: 2013-12-17, 02:42 PM
  3. Help with a lisp routine to add a 12" line to this routine
    By Orbytal.edge341183 in forum AutoLISP
    Replies: 3
    Last Post: 2012-11-14, 10:33 PM
  4. Replies: 9
    Last Post: 2012-01-21, 07:58 AM
  5. Brick Lisp modification requested
    By BCrouse in forum AutoLISP
    Replies: 0
    Last Post: 2008-04-17, 08:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts