Legal
notices:
- This sample program is intended as a demonstration only.
- The program is available on an 'as-is' basis with no warranties,
either expressed or implied, of any kind.
- You may use the program only at your own risk.
- No license or rights to the program are either given or forfeited.
Everything that follows is direct and unaltered output from the LISP
Generator.
; This program was created on December 8 2006 using the LISP Generator.
; Define the function (the program).
(defun c:INCH-CM ( / ENT OLDTEXT INCHES CMS CM-STR NEWTEXT OLDCE OLDERR
OLDTE)
; Save the current value of cmdecho then redefine it.
(setq OLDCE (getvar "cmdecho"))
(setvar "cmdecho" 1)
; Save the current value of texteval then set it to 1
(setq OLDTE (getvar "texteval"))
(setvar "texteval" 1)
; Save the current value of the error handling subroutine then
redefine it.
(setq OLDERR *error*)
(defun *error* (errmes)
(princ (strcat "\nExecution of INCH-CM halted by the
following error: " ERRMES))
(setvar "cmdecho" OLDCE)
(setq *error* OLDERR)
(prin1)
)
;(setq *error* nil)
; NOTE: to turn error handling off, erase the semicolon in the
line above. 
; GET a ENTITY from the user and store it in ENT.
(setq ENT (car (entsel "\nSelect object to modify: ")))
; EXTRACT the Text string from the entity ENT and store it in
OLDTEXT.
(setq OLDTEXT (cdr (assoc 1 (entget ENT))))
; CONVERT the string OLDTEXT to a real number and store it in
INCHES
(setq INCHES (atof OLDTEXT))
; assign result of MATH calculation to CMS.
(setq CMS (* INCHES 2.54))
; CONVERT the real number CMS to a string and store it in CM-STR
(setq CM-STR (rtos CMS 2 2))
; OPERATION - store the result in NEWTEXT.
(setq NEWTEXT (STRCAT OLDTEXT " {" CM-STR " cm}"))
; MODIFY the code 1 value (Text string) of the entity ENT.
(if (assoc 1 (entget ENT))
(entmod (subst (cons 1 NEWTEXT) (assoc 1 (entget
ENT)) (entget ENT)))
(entmod (cons (cons 1 NEWTEXT) (entget ENT)))
)
; Reset "cmdecho" to previous value. 
(setvar "cmdecho" OLDCE)
; Reset "texteval" to previous value.
(setvar "texteval" OLDTE)
; Reset *error* to previous definition.
(setq *error* OLDERR)
; Exit quietly (no return value.)
(prin1)
)