Often, I am asked how you can tell if a specific Object Snap value (OSMODE) is set or determine the state of the Shortcut Menu (SHORTCUTMENU). These along with other values can be hard to tell at times because of the way the values are stored and summed up. These variables use bitcodes to determine what the behavior is going to be. Bitcodes can be summed up as a way to store many values as a single compact value that makes loading and reading them fast, for programs anyways. For someone to sit down and figure out the combinations of all the values it would take sometime and this is the reason behind the LOGAND and LOGIOR functions.
The LOGAND function is much more useful that I have found than the LOGIOR function. Below is an example of a command that checks the OSMODE value to see if the INTersection object snap is set or not. If it is not on, it gets turned on and if it is on it gets turned off.
;; Written by Lee Ambrosius
;; Created on: 6/6/04
;; Command toggles the INTersection value of the OSMODE value
(defun c:INT ()
;;Check to see if INTersection (32) bitcode is currently part of the OSMODE variable
(if (zerop (logand 32 (getvar "OSMODE")))
(setvar "OSMODE" (+ (getvar "OSMODE") 32))
(setvar "OSMODE" (- (getvar "OSMODE") 32))
)
(princ)
)
Sincerely,
Lee
Great function. Haven't had the time to figure this one out, so glad I found your blog. I modified your code to work with all types of bitcode variables... had to add a ON/OFF switch for the case when you just want it On, not toggled.
(defun BITCODE (value bit on)
;; Written by Lee Ambrosius
;; Created on: 6/6/04
;; Command toggles the bit of the value (typical used for OSMODE)
;; Value of 'on' determines if bit is to be on (1), off (-1), or toggled (0 or nil)
(cond
((= on "1")(+ value bit))
((= on "-1")(- value bit))
(T
(if (zerop (logand bit value))
(+ value bit)
(- value bit)
)))
)
Posted by: Itlan | Tuesday, May 08, 2007 at 05:19 PM
Lee, your lisp routine is great. However, it does not take into account the fact that the Bit may already be set. I have modified your code slightly to check this first...
(defun bitcode (value bit on)
;; Written by Lee Ambrosius on: 6/6/04
;; Command toggles the bit of the value (typically used for OSMODE)
;; Value of 'on' determines if bit is to be on (1), off (-1), or toggled (0 or nil)
(cond
((or(= on "1")(= on 1))(if(zerop(logand bit value))(+ value bit)value));; Turn bit on if not already on
((or(= on "-1")(= on -1))(if(not(zerop(logand bit value)))(- value bit)value));; Turn bit of if not already off
(T(if(zerop(logand bit value))(+ value bit)(- value bit);; Toggle bit
)))
) ;defun bitcode
Posted by: Jim | Thursday, August 16, 2007 at 09:31 PM