Hi all,
Is it possible to write a macro, LISP or Diesel or whatever, to control a function key to toggle the snapang between 0 & 45 degrees? What we have now are two F keys to do the job. Thanks.
kwong.
|
|
|
Hi all,
Is it possible to write a macro, LISP or Diesel or whatever, to control a function key to toggle the snapang between 0 & 45 degrees? What we have now are two F keys to do the job. Thanks.
kwong.
The simplest thing to do is create an IF statement to check if the SNAPANG is set to 0.0. If if is, then set it to 45 degrees. Hope this helps.
(defun c:045 ()
(if (= (getvar "SNAPANG") 0.0)
(setvar "SNAPANG" (* pi 0.25))
(setvar "SNAPANG" 0.0)
)
(princ)
)
So true! However, I would like to caution everyone that when you perform an equality test on a real, you would be wise to include a fuzz value:Originally Posted by dkh007.66346
I was bitten by this not too long ago, not following my own advice, even after 20+ years of programming!Code:(if (equal (getvar "SnapAng") 0.0 1e-8)
Great tip! Thanks.Originally Posted by RobertB
Guys,
Thanks a million, I've just saved an F key for something else.
kwong (very satisfied customizer)
Here is another option.
You may enter SA [space] 45 [Enter] to set to 45 deg.
This will set to any angle you enter or you can pick the angle.
Entering SA [space] [Enter] or SA [Enter] [Enter] or SA 0 [Enter] sets to zero
Code:(defun c:sa (/ ang) (if (setq ang (getangle "\nEnter or pick the snap angle: ")) (setvar "SNAPANG" (* 180.0 (/ ang pi))) (setvar "SNAPANG" 0.0) ; SA [Enter] [Enter] ) (princ) ) (prompt "\nSnapAngle lisp loaded, Enter SA [space] the angle and Enter.") (princ)
Here is some button code for a 45 to 0 toggle.
It will flip back and forth between 0 and 45 deg.
Code:^C^C(setvar "SNAPANG" (cond ((equal (getvar "SnapAng") 0.0 1e-8) 45) (0)))
Another one that let's you pick an entity... This is about 14 years old, one of my first LISP routines. Of course with POLAR set to 45, I don't use it as much any more.
Code:(defun c:= (/ r e p1 p2) (graphscr) (initget "Entity") (setq r (getangle "nSnap rotation angle/<Entity>: ")) (cond ((numberp r) (setvar "snapang" r)) ((and (or (not r) (eq r "Entity")) (setq e (entsel)) (setq p1 (osnap (cadr e) "qui,end")) (setq p2 (osnap (cadr e) "qui,mid"))) (setvar "snapang" (angle p1 p2))) (t (princ "nInvalid selection.")) ) (princ) )
G'day ab2draft,
I like that, it fits nicely into the button macro without having to load any lisp routine. Thanks.
kwong
You're welcome.
If you want to put a lisp in a button without loading the lisp first use this code.
If the lisp is not loaded it will load it first.Code:^C^C(if (not c:lisp_call)(load "lisp_name"));lisp_call
If you saved the SA lisp above as sa.lsp you would use this:
Code:^C^C(if (not c:sa)(load "sa.lsp"));sa