Author Topic: Se7en's OsMode Routine  (Read 3584 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Se7en's OsMode Routine
« on: December 30, 2003, 11:02:30 AM »
This is how I am using Se7en's osmode toggle.

Code: [Select]
(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))

)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9672
Se7en's OsMode Routine
« Reply #1 on: December 30, 2003, 11:36:09 AM »
no. hold on.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9672
Se7en's OsMode Routine
« Reply #2 on: December 30, 2003, 11:40:06 AM »
cab, Use this procedure, NOT those. (Well you can if you want to, but this is easier)

Code: [Select]
;;;===================================================================;
;;; 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
Code: [Select]
(defun c:myline ()
  (SetOsnaps 0)
  ;; I do NOT want snaps enabled
  (command "line")
  )
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Se7en's OsMode Routine
« Reply #3 on: December 30, 2003, 12:11:34 PM »
Ok here is what I had to do to get the same results for my test.
Works well... Thanks

CAB


Code: [Select]

;;;===================================================================;
;;; 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've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9672
Se7en's OsMode Routine
« Reply #4 on: December 30, 2003, 12:21:42 PM »
I think your missing the point CAB.

Look at this:

Quote
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:
Quote
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:
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Se7en's OsMode Routine
« Reply #5 on: December 30, 2003, 12:37:02 PM »
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
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9672
Se7en's OsMode Routine
« Reply #6 on: December 30, 2003, 12:41:25 PM »
Oh ok. good.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org