leonucadomi Posted 14 hours ago Posted 14 hours ago 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 13 hours ago Posted 13 hours ago '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) ) Quote
Tsuky Posted 13 hours ago Posted 13 hours ago 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) ) Quote
Lee Mac Posted 1 hour ago Posted 1 hour ago Another - (defun c:sf ( ) (setvar 'ucsfollow (- 1 (getvar 'ucsfollow))) (princ) ) 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.