Jump to content

Recommended Posts

Posted

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

 

 

Posted

'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) 
) 

 

Posted

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)
)

 

Posted

Another -

(defun c:sf ( )
    (setvar 'ucsfollow (- 1 (getvar 'ucsfollow)))
    (princ)
)

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...