Author Topic: How to use timer in LSP program?  (Read 1569 times)

0 Members and 1 Guest are viewing this topic.

baitang36

  • Bull Frog
  • Posts: 213
How to use timer in LSP program?
« on: January 19, 2022, 08:15:00 PM »
For example, run a function every minute

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

baitang36

  • Bull Frog
  • Posts: 213
Re: How to use timer in LSP program?
« Reply #2 on: January 19, 2022, 11:20:54 PM »
From a quick Google search
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/run-lisp-every-hour/m-p/7385593/highlight/true#M358836

I didn't test it.
thank you
Code - Auto/Visual Lisp: [Select]
  1. (defun @sysvar_reactor (Reactor Info / Reaction Test DATE)
  2.    (or *doc* (setq *doc* (vla-get-activedocument *acad*)))
  3.               DATE (getvar "DATE")  ;; Units are days
  4.    )
  5.    ;; The next two lines are for creating a global list of sysvars that have triggered the reaction
  6.    ;; Note that sysvars such as DATE, CDATE, TDUSRTIMER, and VIEWCENTER  do NOT trigger.
  7.    (setq sysvar (car info))
  8.    (or (vl-position sysvar sysvars)(setq sysvars (cons sysvar sysvars)))
  9.    (cond
  10.      ((not **LAST_DATE**)(setq **LAST_DATE** DATE))
  11.      ((not **INTERVAL**))
  12.      ((/= (type **ALARM_FUNCTION**) 'LIST))
  13.      ((>= DATE (+ **LAST_DATE** (/ **INTERVAL** 1440.0)))
  14.        (eval **ALARM_FUNCTION**)
  15.        (setq **LAST_DATE** DATE)
  16.      )
  17.    )
  18.    (princ)
  19. )
  20. (defun c:setalarm ( / str interval ok)
  21.   (while (not ok)
  22.     (initget 1)
  23.     (setq str (getstring T "\nEnter alarm function to run: "))
  24.     (if (= (type (read str)) 'LIST)
  25.       (setq  ok 1)
  26.       (prompt "\nInvalid function.  Please reenter.")
  27.     )
  28.   )
  29.   (initget 5) ;; require input and disallow negative values
  30.   (setq interval (getint "\nEnter alarm interval in minutes (0 to turn off): "))
  31.   (@setalarm str interval)
  32. )
  33. (defun @setalarm (func interval / ok)
  34.     (if (and (= (type func) 'STR)(= (type (read func)) 'LIST))
  35.       (setq **ALARM_FUNCTION** (read func) ok 1)
  36.       (prompt "\nInvlaid function")
  37.     )
  38.     (if (and  ok (numberp interval)(> interval 0))
  39.       (setq **INTERVAL** interval ok 1)
  40.       (setq ok (prompt "\nInterval must be greater than or equal to 0."))
  41.     )
  42.     (cond
  43.       ((not ok))
  44.       ((> **INTERVAL** 0)
  45.         (if (/= (type $sysvar_reactor) 'VLR-SysVar-Reactor)
  46.           (setq $sysvar_reactor
  47.             (vlr-SysVar-reactor "Uhden Sysvar Reactor"
  48.               '((:vlr-sysVarChanged . @sysvar_reactor))
  49.             )
  50.           )
  51.         )
  52.         (or (vlr-added-p $sysvar_reactor)(vlr-add $sysvar_reactor) 1)
  53.         (setq  **LAST_DATE** (getvar "DATE"))
  54.         (princ (strcat "\nAlarm has been set at " (menucmd "M=$(edtime,$(getvar,date),HH:MM:SS)")))
  55.         (princ (strcat "\nAlarm will go off in " (itoa **INTERVAL**) " minute(s)."))
  56.       )
  57.       ((and
  58.           (= (type $sysvar_reactor) 'VLR-SysVar-Reactor)
  59.           (vlr-added-p $sysvar_reactor)
  60.           (or (vlr-remove $sysvar_reactor) 1)
  61.           (not (setq $sysvar_reactor nil))
  62.           (princ "\nAlarm has been turned off.")
  63.         )
  64.      )
  65.   )
  66.   (princ)
  67. )
  68.  
I tried it, but it didn't work