Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Variable type checking

3 REPLIES 3
Reply
Message 1 of 4
Merlin
439 Views, 3 Replies

Variable type checking

Hello!
Is there any way of implementing variable type checking?
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Merlin

Load this and type SYSVAR at the command prompt. It will echo any sysvar
change to the command line.

(defun sysvarChanged (reactor info)
(princ (strcat "\n" (car info) " "))
(princ (getvar (car info)))
(princ ", ")
(princ)
)

(defun c:sysvar (/ ans)
(initget 0 "on off")
(setq ans (getkword "\nTurn sysvar echo [on/]: "))
(cond
((not ans)(setq ans 5))
((= (strcase ans) "ON")(setq ans 3))
(T (setq ans 5))
)
(reac:state '(vlr-sysvar-reactor nil '((:vlr-sysvarChanged .
sysvarChanged))) ans)
(princ)
)

;;;tests for constructed "reactor"
;;;syntax: (REAC:STATE 'reactor mode)
;;;arguments: reactor - quoted typical reactor construction syntax, mode -
intiger 0-7
;;;usage: (REAC:STATE '(VLR-Command-Reactor nil '((:VLR-commandWillStart .
TEST))) 1)
;;;"mode" 0 constructs "reactor" once even if already constructed
;;;"mode" 1 constructs "reactor" once if "reactor" has not already been
constructed
;;;"mode" 2 removes first constructed "reactor" with matching "event" and
"call", then constructs once
;;;"mode" 3 removes *all* constructed "reactor"s with matching "event" and
"call", then constructs once
;;;"mode" 4 removes first constructed "reactor" with matching "event" and
"call"
;;;"mode" 5 removes *all* constructed "reactor"s with matching "event" and
"call"
;;;"mode" 6 removes *all* constructed "reactor"s with matching "event"
regardless of "call"
;;;"mode" 7 removes *all* constructed "reactor"s regardless of "call" or
"event"
;;;returns last VLR object acted upon, else nil
(defun reac:state (reactor mode / call reaction rname vlrobj)
(setq call (eval (caddr reactor))
event (caar call)
rname (read (strcat ":" (vl-symbol-name (car reactor))))
)
(if (> mode 0)
(foreach itm (cdar (vlr-reactors rname))
(setq reaction (vlr-reactions itm))
(cond
(
(and (= mode 1)(equal call reaction))
(setq reactor nil)
)
(
(or
(and (= mode 2)(not vlrobj)(equal call reaction))
(and (= mode 3)(equal call reaction))
(and (= mode 4)(not vlrobj)(equal call reaction))
(and (= mode 5)(equal call reaction))
(and (= mode 6)(equal event (caar reaction)))
(= mode 7)
)
(setq vlrobj (vlr-remove itm))
)
)
)
)
(if (and (< mode 4) reactor)(setq vlrobj (eval reactor)))
vlrobj
)
--

Regards,
Eric S.
eschneider@jensenprecast.com
Message 3 of 4
Anonymous
in reply to: Merlin

For checking the type of a variable, use the "type" function.

(type "1") ;returns 'STR
(type 1) ;returns 'INT
(type 1.0) ;returns 'REAL

etc.

Merlin wrote...
>Hello!
>Is there any way of implementing variable type checking?
>
Message 4 of 4
Merlin
in reply to: Merlin

Thank you Randy. It works perfectly. :-))

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost