Toggling system variables

Discussion in 'AutoCAD' started by Mack Attack, Aug 5, 2004.

  1. Mack Attack

    Mack Attack Guest

    I am trying to set up some routines that will take a current variable (i.e.
    osnaphatch) and toggle the current setting (i.e. 0 to 1 or 1 to 0). Could
    you guys please give me a starting point.

    Thanks as always
    Mack
     
    Mack Attack, Aug 5, 2004
    #1
  2. Mack Attack

    BillZ Guest

    (setvar "osnaphatch"(boole 6 1(getvar "osnaphatch")))

    Bill
     
    BillZ, Aug 5, 2004
    #2
  3. In lisp:

    (setvar "osnaphatch" (- 1 (getvar "osnaphatch")))

    In diesel (for menus):

    'osnaphatch $M=$(xor,$(getvar, osnaphatch),1)
     
    Allen Johnson, Aug 5, 2004
    #3
  4. Another possible approach:

    (if (= (getvar "osnaphatch") 1) (setvar "osnaphatch" 0) (setvar "osnaphatch"
    1))

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Aug 5, 2004
    #4
  5. I wondered about the acceptability of setting one of these 0 or 1 variables
    to -1. (I'm on 2004, so I don't have OSNAPHATCH to check with, but I tried
    it with SNAPMODE.) Two things:

    1. While it does NOT accept typing in -1 as a value, it DOES accept Allen's
    lisp approach (if it's currently zero, and you subtract one from it, somehow
    it returns just plain 1, rather than -1). Does anyone know why?

    2. In the case of SNAPMODE in particular, if you put that in as a "command"
    or as an option in the SETVAR command, and try to enter -1, it says:

    Requires an integer between 0 and 2.

    Help does NOT mention 2 as a possible value, but you can, in fact, set it to
    2. Does anyone know what it does? Help says 1 is "Snap on for the current
    viewport", so might 2 be for "Snap on for all viewports"? Does 2005 Help
    list 2 as a value?


    Another thing: if you want a "toggle" to be more like a "cycle" for
    something with more than just 0 and 1 values (apparently now SNAPMODE, but
    also for example SNAPISOPAIR for the Isometric Plane), you can do something
    [equivalent to F5] like:

    (if (= (getvar "snapisopair") 2) (setvar "snapisopair" 0) (setvar
    "snapisopair" (1+ (getvar "snapisopair"))))

    For a variable with more than 0, 1 & 2 (if there are any that go up to 3 or
    something), change that 2 to whatever the highest allowable value is. (You
    COULD even do it for something that adds up power-of-two values, like
    OSMODE, but that seems kind of silly.)

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Aug 5, 2004
    #5
  6. Command: (- 1 0)
    1

    Command: (- 1 1)
    0
     
    Jason Piercey, Aug 5, 2004
    #6
  7. Mack Attack

    David Bethel Guest

    1 from my macro library:

    (defun toggle (v)
    (and (= (type v) 'STR)
    (getvar v)
    (or (= (getvar v) 0)
    (= (getvar v) 1))
    (setvar v (- 1 (getvar v))))
    (getvar v))

    -David
     
    David Bethel, Aug 5, 2004
    #7

  8. As Jason pointed out, I'm not subtracting one from the value, but rather the value FROM one.
     
    Allen Johnson, Aug 5, 2004
    #8
  9. But actually using the boole 6 function, as BillZ shows, is better, since boole 6 is the XOR
    function.
    I always forget about yhe boole functions!
     
    Allen Johnson, Aug 5, 2004
    #9
  10. I guess I was thinking of (- 1 ...) [with a space between the - and the 1]
    as being the same as (-1 ...) [without the space] -- got the order of what
    was being subtracted from what wrong.

    But I'm still interested in what a SNAPMODE value of 2 means...

    Kent Cooper, AIA


    ...
    ....
    the value FROM one.
     
    Kent Cooper, AIA, Aug 5, 2004
    #10
  11. Help files from 2005 do not list a value of 2, FWIW.
     
    Jason Piercey, Aug 5, 2004
    #11
  12. Mack Attack

    Tom Smith Guest

    Another possible approach:
    "osnaphatch" 1))

    Possible, but less elegant than previously posted solutions. A shorter
    version of the same thing, avoiding the repetitive setvar, would be:

    (setvar "osnaphatch" (if (= (getvar "osnaphatch") 1) 0 1))

    There are any number of possible ways to get there, but I haven't seen any
    more concise than the direct methods of using a boolean operation or
    subtracting from 1.
     
    Tom Smith, Aug 5, 2004
    #12
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.