OSMODE bitcodes

Discussion in 'AutoCAD' started by Daniel Hargreaves, Jun 27, 2004.

  1. It must be the weather, because I can't get my head around how to get the
    individual OSNAP settings from the OSMODE. If I use (getvar "OSMODE") and
    let's say it returns 39. I know that Endpoint, Midpoint, Center and
    Intersections are set because it is the sum of 1, 2, 4 and 32. So my
    question is how do I break down the 39 to 1, 2, 4 and 32?

    Any help is greatly appreciated.
    Daniel Hargreaves, CSI
     
    Daniel Hargreaves, Jun 27, 2004
    #1
  2. Daniel Hargreaves

    David Bethel Guest

    Daniel,

    Try this:

    (defun c:sm (/ int)
    (textpage)
    (setq int (getvar "OSMODE"))
    (prompt "\nOSnap Modes:")
    (if (= int 0)
    (princ " - None")
    (princ (strcat " - " (itoa int))))
    (prompt (strcat
    "\n\n\tCENter : " (itoa (logand int 512))
    "\n\tENDpoint : " (itoa (logand int 1))
    "\n\tINSertion : " (itoa (logand int 32))
    "\n\tINTersection : " (itoa (logand int 64))
    "\n\tMIDpoint : " (itoa (logand int 1024))
    "\n\tNEArest : " (itoa (logand int 4))
    "\n\tNODe : " (itoa (logand int 256))
    "\n\tPERpendicular: " (itoa (logand int 16))
    "\n\tQUAdrent : " (itoa (logand int 128))
    "\n\tQUIck : " (itoa (logand int 2))
    "\n\tTANgent : " (itoa (logand int 8))
    ;;;A2K ADDITIONS
    "\n\tAPPanrent : " (itoa (logand int 2048))
    "\n\tEXTension : " (itoa (logand int 4096))
    "\n\tPARallel : " (itoa (logand int 8192))))
    (prin1))

    -David
     
    David Bethel, Jun 27, 2004
    #2
  3. Daniel Hargreaves

    David Bethel Guest

    Oh,

    If it returns 0, the mode IS NOT set. -David
     
    David Bethel, Jun 27, 2004
    #3
  4. Thanks David!
    I was just starting to explore the use of logand... And you beat to the
    punch. Thanks for your help with this. Now I can move forward :)

    Daniel.
     
    Daniel Hargreaves, Jun 27, 2004
    #4
  5. Daniel Hargreaves

    Josh Guest

    ;;;returns list of the bit-codes (1,2,4,8,16,32,64,128,256,512 and/or 1024)
    ;;;in num as an integer list
    (defun logand_list (num / loglist cnt)
    (setq cnt 1)
    (while (<= cnt num)
    (if (= (logand num cnt) cnt)
    (setq loglist (cons cnt loglist))
    )
    (setq cnt (* cnt 2))
    )
    (reverse loglist)
    )
     
    Josh, Jun 28, 2004
    #5
  6. .... and if the OSMODE variable is negative the osnaps are turned set but
    turned off ...
     
    Martin Shoemaker, Jul 2, 2004
    #6
  7. Daniel Hargreaves

    David Bethel Guest


    That's a new one on me..... -David
     
    David Bethel, Jul 2, 2004
    #7
  8. Should have edited my post a bit better.... That's why this works:

    (defun c:toggle-osnap ()
    (setvar "osmode" (boole 6 (getvar "osmode") 16384))
    )

    Martin
     
    Martin Shoemaker, Jul 2, 2004
    #8
  9. Thanks Martin. I will see if I have a need for this, it is a very useful bit
    of code. I knew about the on/off toggle setting. The nice thing about using
    the LOGAND is it won't matter if the user has the OSNAP toggled on or off.
    It will still echo the states used.

    Daniel.
     
    Daniel Hargreaves, Jul 4, 2004
    #9
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.
Similar Threads
Loading...