Below are a few functions that create/use a reactor as a kind of alarm to call another function after X many minutes input by user.
The whole thing is based on a vlr-sysvar reaction.
The first function is the reactor callback function.
The second (C:) function can be used at the command line to set the time interval and take the "alarm" function (as a string) to perform inside the reaction.
The third function can be called from within any lisp and takes arguments for the "alarm" function and interval in minutes.
When using the command function, you can enter the "alarm" function without quotes, as in (alert "TIME TO WAKE UP\nIT'S WAGON WHEEL TIME")
When using the third function (@setalarm), you must provide the "alarm" function argument as a string, as in "(alert \"WAKE UP\")"
Sadly, but understanably, the vlr-sysvar-reactor does not respond to sysvars like DATE, or CDATE, or TDUSRTIMER, or VIEWCENTER. But I figure we all turn on and off OSMODE plenty, or switch layouts. I hope this is good enough to be helpful to someone.
I have not tested it with anything more than (alert), so I can't tell you what might happen with something more complicated. I am very sure that if the function you call changes any applicable sysvar, then the reactor will fire again and again and will probably blow up your session. If needed, I do have a way around that.
(defun @sysvar_reactor (Reactor Info / Reaction Test DATE)
(or *doc* (setq *doc* (vla-get-activedocument *acad*)))
(setq Reaction (vlr-current-reaction-name)
DATE (getvar "DATE") ;; Units are days
)
;; The next two lines are for creating a global list of sysvars that have triggered the reaction
;; Note that sysvars such as DATE, CDATE, TDUSRTIMER, and VIEWCENTER do NOT trigger.
(setq sysvar (car info))
(or (vl-position sysvar sysvars)(setq sysvars (cons sysvar sysvars)))
(cond
((not **LAST_DATE**)(setq **LAST_DATE** DATE))
((not **INTERVAL**))
((/= (type **ALARM_FUNCTION**) 'LIST))
((>= DATE (+ **LAST_DATE** (/ **INTERVAL** 1440.0)))
(eval **ALARM_FUNCTION**)
(setq **LAST_DATE** DATE)
)
)
(princ)
)
(defun c:setalarm ( / str interval ok)
(while (not ok)
(initget 1)
(setq str (getstring T "\nEnter alarm function to run: "))
(if (= (type (read str)) 'LIST)
(setq ok 1)
(prompt "\nInvalid function. Please reenter.")
)
)
(initget 5) ;; require input and disallow negative values
(setq interval (getint "\nEnter alarm interval in minutes (0 to turn off): "))
(@setalarm str interval)
)
(defun @setalarm (func interval / ok)
(if (and (= (type func) 'STR)(= (type (read func)) 'LIST))
(setq **ALARM_FUNCTION** (read func) ok 1)
(prompt "\nInvlaid function")
)
(if (and ok (numberp interval)(> interval 0))
(setq **INTERVAL** interval ok 1)
(setq ok (prompt "\nInterval must be greater than or equal to 0."))
)
(cond
((not ok))
((> **INTERVAL** 0)
(if (/= (type $sysvar_reactor) 'VLR-SysVar-Reactor)
(setq $sysvar_reactor
(vlr-SysVar-reactor "Uhden Sysvar Reactor"
'((:vlr-sysVarChanged . @sysvar_reactor))
)
)
)
(or (vlr-added-p $sysvar_reactor)(vlr-add $sysvar_reactor) 1)
(setq **LAST_DATE** (getvar "DATE"))
(princ (strcat "\nAlarm has been set at " (menucmd "M=$(edtime,$(getvar,date),HH:MM:SS)")))
(princ (strcat "\nAlarm will go off in " (itoa **INTERVAL**) " minute(s)."))
)
((and
(= (type $sysvar_reactor) 'VLR-SysVar-Reactor)
(vlr-added-p $sysvar_reactor)
(or (vlr-remove $sysvar_reactor) 1)
(not (setq $sysvar_reactor nil))
(princ "\nAlarm has been turned off.")
)
)
)
(princ)
)