;;; Source code from the book "AutoCAD expert's Visual LISP"
;;; (c) 2012 Ediciones ARTUAL, S.L. Barcelona, EspaƱa.
;;; Copyright © 2012-2020 by Reinaldo N. Togores. All rights reserved.
;;; Use of this code is allowed mentioning the book and its author.
;;;Chapter 7. Data entry.
(defun default-value (func message value / tmp)
(if
(setq tmp (apply
func
(list
(strcat message
"<"
(vl-princ-to-string value)
">: "))))
tmp
value))
;;;Listing 7.1. User input request including default values.
(defun default-string (message value / tmp)
(setq tmp (apply 'getstring
(list (strcat message "<" value ">: "))))
(if (/= tmp "")
tmp
value))
;;;Listing 7.2. Prompting for a string with default value.
(defun value-with-options (func message options / tmp)
(initget options)
(if
(setq tmp (apply
func
(list
(strcat message
" ["
(vl-string-translate "/" " " options)
"]: "))))
tmp))
;;;Listing 7.3. Prompting for data including options.
(defun getfixnum (message / tmp)
(initget 1)
(setq tmp (getreal message))
(while (and tmp (not (< -2147483647.0 tmp 2147483647.0)))
(prompt
"Requires an integer from -2147483647 to 2147483647..\n")
(initget 1)
(setq tmp (getreal message)))
(if (numberp tmp)
(fix tmp)
tmp))
;;;Listing 7.4. Function that admits long integers.
(defun id-bits (value /)
(vl-remove 0
(mapcar '(lambda (i) (logand i value))
'(1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
65536))))
;;;Listing 7.5. Function to detect the enabled bits.
(defun bits-on? (bits value)
(= bits (logand bits value)))
(defun enable-bits (bits value)
(logior bits value))
(defun disable-bits (bits value)
(logand (~ bits) value))
;;;Listing 7.6. Functions to check, enable or disable bits.
(defun switch-sysvars (varsis bits)
(setvar varsis (boole 6 (getvar varsis) bits)))
;;;Listing 7.7. Variables switch.
(defun cmd-in (/ 3dosm)
(if
(and (setq 3dosm (getvar "3DOSMODE"))
(not (bits-on? (lsh 1 0) 3dosm)))
(switch-sysvars "3DOSMODE" (lsh 1 0)))
(if (not (bits-on? (lsh 1 14) (getvar "OSMODE")))
(switch-sysvars "OSMODE" (lsh 1 14)))
(if (bits-on? (lsh 1 0) (getvar "CMDECHO"))
(switch-sysvars "CMDECHO" (lsh 1 0))))
;;;Listing 7.8. Setting system variables before entering the command.
(defun cmd-out (/ 3dosm)
(if
(and (setq 3dosm (getvar "3DOSMODE"))
(bits-on? (lsh 1 0) 3dosm))
(switch-sysvars "3DOSMODE" (lsh 1 0)))
(if (bits-on? (lsh 1 14) (getvar "OSMODE"))
(switch-sysvars "OSMODE" (lsh 1 14)))
(if (not (bits-on? (lsh 1 0) (getvar "CMDECHO")))
(switch-sysvars "CMDECHO" (lsh 1 0))))
;;;Listing 7.9. Restoring the original values on exiting the command.
No comments:
Post a Comment