;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; =.lsp By Michael Bulatovich March 29th, 2002 ; ; www.michaelbulatovich.ca ; ; ; ; Converts feet and inches to meters or millimeters transparently. ; ; For use in any command that requires a distance in a ; ; metric drawing, and where the balding head of the user thinks ; ; better in imperial units. ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun pickunits (/) (initget 1 "1 2") (setq conversiontype (getkword "\nSpecify Metric Units: <1> Meters | <2> Millimeters" ) ) ) ;------------------------------------------------------------------------------- (defun convert (arg / num) (if (eq conversiontype "1") (setq arg (* arg 0.0254)) (setq arg (* arg 0.254)) ) ) ;------------------------------------------------------------------------------ (defun str-index (target search / tarlen serlen cntr strlist place sersub tarsub tlen-1) (setq tarlen (strlen target) serlen (strlen search)) (if (<= 1 tarlen serlen);if search is greater r eaqual to first, likewise target to 1 (progn (setq tarsub (substr target tarlen 1) tlen-1 (1- tarlen); ) (setq strlist nil ;initialize a nil variable cntr 0) ;set a cntr to zero (while (< (setq cntr (1+ cntr)) tarlen);bump cntr by one, as ong as its less than the search item length (setq strlist (cons (cons (substr target cntr 1) (- tarlen cntr)) strlist)) );construct a assoc-list of characters with their inverse positions (setq cntr tarlen) (while (<= 1 cntr serlen) (setq cntr (if (or (/= (setq sersub (substr search cntr 1)) tarsub) (/= (substr search (- cntr tlen-1) tarlen) target) ) ;end or (+ cntr (if (setq place (assoc sersub strlist)) (cdr place) tarlen) ) ;end then (- tlen-1 cntr) ;end else ) ;end if ) ;negative value for ending(?) ) ;end while ;;return position or nil (if (< cntr 0)(- cntr)) );end progn );end if );end defun ;------------------------------------------------------------------------------ (defun c:= (/ input footindex feet total trim inches strlength) (setvar "cmdecho" 0) (prompt "\nConvert Imperial units to Metric units. ") (if (equal conversiontype nil) (pickunits) ) (setq total 0.0) (setq input (getstring "Specify Imperial dimension:")) ; get the imperial (setq footindex (str-index "'" input)) ; find the foot mark (if (not (eq nil footindex)) ; if feet were entered (progn ; then... (setq feet (substr input 1 footindex)) ;isolate the feet (setq total (* 12 (atof feet))) ; convert the string (setq inches (substr input (+ 2 footindex))) ;isolate the inches (setq strlength (strlen inches)) ;set strlenght (if (eq strlength 0) ; if its zero (convert total) (progn ;if its not zero (setq trim (- strlength 1)) (if (eq "\"" (substr inches strlength 1)) ;and if it ends in " (setq inches (substr inches 1 trim)) ;cut it off ) (setq total (+ total (atof inches))) ;convert and add to total (convert total) ) ) ) ;end of progn (progn ; if no feet were entered (setq inches input) (setq strlength (strlen inches)) (setq trim (- strlength 1)) (if (eq "\"" (substr inches strlength 1)) ;if it ends in a " (setq inches (substr inches 1 trim)) ) ; cut it off (setq total (+ total (atof inches))) ;convert and add to total (convert total) ) ) ;end if )