;;--------------rtodtstl.lsp----------------------------- ;;; Author: Herman Mayfarth ;;; Date: 15 Jan 2002 ;;; Purpose: convert real to MTEXT representation as ft & inches ;;; w/ unbarred fraction & no inch marks ;;; Params: num: real number to convert to MTEXT string ;;; fracht: real specifying the relative ht. of fractions ;;; Returns: string as above if successful, nil otherwise ;;;------------------------------------------------------ (defun rtodtstl (num fracht / add count curent instrg outstrg start_format suffix ) (setq instrg (rtos num 4 4) ;strip the last character, which is alwayss the inch mark instrg (substr instrg 1 (1- (strlen instrg))) ) ;;three cases exist: ;;Case 1: ;;if we have > 1" and have a fraction, the string will contain a space before ;;the fraction, and we need to substitute the start of the MTEXT format for ;;the space character ;;Case 2: ;;we have >1" but no fraction => no / will be found, and no MTEXT formatting ;;Case 3: ;;we have a fraction <1" => MTEXT formatting prefixes the input string ;setup the format string for the start of the MTEXT fraction (setq start_format (strcat "{\\H" (rtos fracht 2 2) "x;\\S") ;initialize a counter for the position to test in the input string count 1 suffix 0 ;and bind a null string to a symbol for the output string outstrg "") ;now walk down the input string one character at a time (repeat (strlen instrg) ;set a flag to indicate the current character should be kept (setq add 1 ;and get the current character from the input string curent (substr instrg count 1)) ;;first, test for a space character (cond ((= curent " ");found a space (Case 1), ;; so substitute the fraction format, clear the add flag, and set a flag ;; to let us know we need to close the format at the end (setq outstrg (strcat outstrg start_format) add nil suffix 1)) ;;else test for fraction bar ((= curent "/") ;found a fraction bar (progn ;;test for suffix (if (= suffix 0) (setq suffix 2));need a prefix ;;substitute the ^ symbol, clear the add flag (setq outstrg (strcat outstrg "^") add nil ) );progn );pred );cond ;if add is bound, there was no substitution, so just add the ;current character to the front of the output string (if add (setq outstrg (strcat outstrg curent))) (setq count (1+ count)) );repeat ;;if we found a fraction, we need to close the MTEXT format (cond ((= suffix 1) (setq outstrg (strcat outstrg ";}"))) ((= suffix 2) (setq outstrg (strcat start_format outstrg ";}"))) (T nil);otherwise, do nothing ) outstrg );rtodtstl