TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CAB on December 30, 2003, 11:02:30 AM
-
This is how I am using Se7en's osmode toggle.
(defun OsnapDisable ()
(if (<= (getvar "osmode") 15359)
(progn ;; If the snaps are enabled then turn them off
(setvar "osmode" (boole 6 (getvar "osmode") 16384))
T
)
nil ; returns T if osmode was changed else return nil
)
)
(defun OsnapEnable ()
(if (>= (getvar "osmode") 15359)
(progn ;; If the snaps are disabled then turn them on
(setvar "osmode" (boole 6 (getvar "osmode") 16384))
T
)
nil ; returns T if osmode was changed else return nil
)
)
(defun c:ost()
(setvar "osmode" 39)
(setq SnapsChanged (OsnapDisable)) ; force os off
;; code here needing os off
;; if the snaps were on we need to turn them back on
(if SnapsChanged (OsnapEnable))
(setvar "osmode" 39)
(setq SnapsChanged (OsnapEnable)); force os on
; code here needing os on
; if snaps were off we need to turn them back off
(if SnapsChanged (OsnapDisable))
(setvar "osmode" 0) ; can not force on when set to zero
(setq SnapsChanged (OsnapEnable)); force os on
; code here needing os on
; if snaps were off we need to turn them back off
(if SnapsChanged (OsnapDisable))
(setvar "osmode" 16423) ;; OFF @39
(setq SnapsChanged (OsnapEnable)); force os on
; code here needing os on
; if snaps were off we need to turn them back off
(if SnapsChanged (OsnapDisable))
(setvar "osmode" 16423) ;; OFF @39
(setq SnapsChanged (OsnapDisable)) ; force os off
;; code here needing os off
;; if the snaps were on we need to turn them back on
(if SnapsChanged (OsnapEnable))
)
-
no. hold on.
-
cab, Use this procedure, NOT those. (Well you can if you want to, but this is easier)
;;;===================================================================;
;;; SetOsnaps ;
;;;-------------------------------------------------------------------;
;;; This function accepts a integer of 1 or 0 (on or off) to set the ;
;;; end users osnap value to enabled or disabled. ;
;;; ;
;;; Argument: 1 = Enable the users osnaps ;
;;; 0 = Disable the users osnaps ;
;;; ;
;;; Usage: (SetOsnaps 1) or (SetOsnaps 0) ;
;;; ;
;;; Author: John Kaul ;
;;;===================================================================;
(defun SetOsnaps (value)
(cond
((= value 1)
(if
(>= (getvar "osmode") 16383)
(setvar "osmode" (boole 6 (getvar "osmode") 16384))
)
)
((= value 0)
(if
(<= (getvar "osmode") 16383)
(setvar "osmode" (boole 6 (getvar "osmode") 16384))
)
)
)
(princ)
)
Here is an example
(defun c:myline ()
(SetOsnaps 0)
;; I do NOT want snaps enabled
(command "line")
)
-
Ok here is what I had to do to get the same results for my test.
Works well... Thanks
CAB
;;;===================================================================;
;;; SetOsnaps (Modified Version) ;
;;;-------------------------------------------------------------------;
;;; This function accepts a integer of 1 or 0 (on or off) to set the ;
;;; end users osnap value to enabled or disabled. ;
;;; ;
;;; Argument: 1 = Enable the users osnaps ;
;;; 0 = Disable the users osnaps ;
;;; ;
;;; Usage: (SetOsnaps 1) or (SetOsnaps 0) ;
;;; ;
;;; Returns: T if osmode was changed ;
;;; nil if no change ;
;;; ;
;;; Author: John Kaul ;
;;;===================================================================;
(defun SetOsnaps (value)
(cond
((OR (AND(= value 1) (>= (getvar "osmode") 16383))
(AND(= value 0) (<= (getvar "osmode") 16383))
)
(setvar "osmode" (boole 6 (getvar "osmode") 16384))
T ; returns T if osmode was changed
)
(T
nil ; returns nil if no change was made
)
)
)
(defun c:ost()
(setvar "osmode" 39)
(setq SnapsChanged (SetOsnaps 0)) ; force os off
;; code here needing os off
;; if the snaps were on we need to turn them back on
(if SnapsChanged (SetOsnaps 1))
(setvar "osmode" 39)
(setq SnapsChanged (SetOsnaps 1)); force os on
; code here needing os on
; if snaps were off we need to turn them back off
(if SnapsChanged (SetOsnaps 0))
(setvar "osmode" 0) ; can not force on when set to zero
(setq SnapsChanged (SetOsnaps 1)); force os on
; code here needing os on
; if snaps were off we need to turn them back off
(if SnapsChanged (SetOsnaps 0))
(setvar "osmode" 16423) ;; OFF @39
(setq SnapsChanged (SetOsnaps 1)); force os on
; code here needing os on
; if snaps were off we need to turn them back off
(if SnapsChanged (SetOsnaps 0))
(setvar "osmode" 16423) ;; OFF @39
(setq SnapsChanged (SetOsnaps 0)) ; force os off
;; code here needing os off
;; if the snaps were on we need to turn them back on
(if SnapsChanged (SetOsnaps 1))
)
-
I think your missing the point CAB.
Look at this:
Command:
Command: osmode
Enter new value for OSMODE <247>:
Command: <Osnap off> <- I hit the <F3> key
Command: osmode
Enter new value for OSMODE <16631>:
Command: <Osnap on> <- I hit the <F3> key
Command: osmode
Enter new value for OSMODE <247>:
Command:
My function dose the EXACT same thing as the <F3> key does! That's it. If you set the osmode to zero there is no using the togle function I wrote. Try to set the osmode to zero and then hit the <F3> key. What happnes?
See:
Command: osmode
Enter new value for OSMODE <0>: 247
Command: (setosnaps 0)
Command: osmode
Enter new value for OSMODE <16631>:
Command: (setosnaps 1)
Command: osmode
Enter new value for OSMODE <247>:
Command:
-
I got your point.
I put the zero test in my test code to see what happens in that case. Just a test.
I try but seldom succeed to test all possibilities.
I only added the return values so i could reset osmode if it was changed.
Your code is working well for me.
CAB
-
Oh ok. good.