leonucadomi Posted Friday at 10:00 PM Posted Friday at 10:00 PM hello : I use this code to quickly change a variable on or off. I would like to know if someone can improve it in appearance or functionality. Quote (defun c:SF (/ gira) (repeat 100 (setq gira (getreal "\nActiva UCS FOLLOW <1>: ")) (if (equal gira nil)(setq gira 1)) (if (= gira 1) (Command "_UCSFOLLOW" "1" "") (princ "\nUCS Follow Activado") ) (setq gira (getreal "\nDesactiva UCS FOLLOW <1>: ")) (if (equal gira nil)(setq gira 1)) (if (= gira 1) (Command "_UCSFOLLOW" "0" "") (princ "\nUCS Follow Desactivado") ) );repeat );fin defun Quote
GLAVCVS Posted Friday at 10:52 PM Posted Friday at 10:52 PM 'repeat 100...'? Changing the same variable 100 times...why? I guess that's a mistake. Something simple: every time the command sf is called, UCSFOLLOW changes state, without asking (defun c:sf (/ act) (setvar "UCSFOLLOW" (if (setq act (= (getvar "UCSFOLLOW") 0)) 1 0)) (princ (strcat "\n*** Variable UCSFOLLOW " (if act "activada" "desactivada"))) (princ) ) 1 Quote
Tsuky Posted Friday at 11:06 PM Posted Friday at 11:06 PM Or this, for toggle (defun c:SF ( / ) (if (zerop (boole 1 (getvar "UCSFOLLOW") 1)) (progn (setvar "UCSFOLLOW" (1+ (getvar "UCSFOLLOW"))) (princ "\nUCS Follow Activado") ) (progn (setvar "UCSFOLLOW" (1- (getvar "UCSFOLLOW"))) (princ "\nUCS Follow Desactivado") ) ) (prin1) ) 1 1 Quote
Lee Mac Posted Saturday at 11:27 AM Posted Saturday at 11:27 AM Another - (defun c:sf ( ) (setvar 'ucsfollow (- 1 (getvar 'ucsfollow))) (princ) ) 1 1 Quote
leonucadomi Posted 3 hours ago Author Posted 3 hours ago On 9/26/2025 at 4:52 PM, GLAVCVS said: 'repeat 100...'? Changing the same variable 100 times...why? I guess that's a mistake. Something simple: every time the command sf is called, UCSFOLLOW changes state, without asking (defun c:sf (/ act) (setvar "UCSFOLLOW" (if (setq act (= (getvar "UCSFOLLOW") 0)) 1 0)) (princ (strcat "\n*** Variable UCSFOLLOW " (if act "activada" "desactivada"))) (princ) ) On 9/26/2025 at 4:52 PM, GLAVCVS said: 'repeat 100...'? Changing the same variable 100 times...why? I guess that's a mistake. Something simple: every time the command sf is called, UCSFOLLOW changes state, without asking (defun c:sf (/ act) (setvar "UCSFOLLOW" (if (setq act (= (getvar "UCSFOLLOW") 0)) 1 0)) (princ (strcat "\n*** Variable UCSFOLLOW " (if act "activada" "desactivada"))) (princ) ) I do it by repeating it 100 times because I don't know how to make a routine repeat itself indefinitely until I execute escape. Quote
leonucadomi Posted 3 hours ago Author Posted 3 hours ago What I'm looking for is not to have a routine that turns it on and one that turns it off, but rather a single routine that, like a roulette wheel, allows me to change the state of the variable just with enter Quote
GLAVCVS Posted 1 hour ago Posted 1 hour ago (edited) Another way, taking advantage of @Lee Mac's idea and condensing an output message for the user (defun c:sf (/ v) (princ (strcat "\n*** " (setq v "UCSFOLLOW") (nth (setvar v (- 1 (getvar v))) '(" desactivado" " activado")))) (princ) ) Edited 1 hour ago by GLAVCVS 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.