;;replachr ;;replaces all occurrences in instrg of each old character from the list ;;oldchars with the corresponding new character from the list newchars ;;& returns the modified string ;;does *not* verify that oldchars & newchars are the same length (defun replachr (oldchars newchars instrg / count flag ndex outstrg) (setq count 1 outstrg "") (repeat (strlen instrg) (setq ndex 0 flag T) (repeat (length oldchars) (if (= (substr instrg count 1) (nth ndex oldchars)) (setq outstrg (strcat outstrg (nth ndex newchars)) flag nil) );if (setq ndex (1+ ndex)) );repeat (if flag (setq outstrg (strcat outstrg (substr instrg count 1)))) (setq count (1+ count)) );repeat outstrg );replachr ;; ;;;--------------------rtodfrm.lsp--------------------------- ;;; ;;; Purpose: function to convert real number to ;;; stacked fraction representation using MTEXT ;;; converts to fractional, not architectural units ;;; Author: Herman Mayfarth ;;; Date: 14 Oct 2001 ;;; Version: 1.0 ;;; Copyright © 2001 Herman Mayfarth ;;; Permission granted to freely use without fee. ;;; Provided "as is" and without warranty, express or implied. ;;;--------------------------------------------------------- ;;; Converts a real to MTEXT *unbarred* fraction representation ;;; Per common practice in U.S. steel fabrication industry ;;; Returns a string to be passed to MTEXT creation function ;;; Calling function must provide MTEXT vertical justification code ;;;--------------------------------------------------------- (defun rtodfrm ( inreal ; real to convert prec ; integer: desired precision of fraction ; must be at least 1 relht ; decimal: ht of fraction relative to whole # ; must have leading zero, i.e. 0.75, not .75 / ;local function fraction_code ;local symbols instrg i j k whole fract len ) (defun fraction_code (frac / ) (setq frac (replachr '("/") '("^") frac)) (strcat "{\\H" (rtos relht 2 2) "x;\\S" frac ";}") );fraction_code ;;;initialize variables (setq i 1 instrg (rtos inreal 5 prec) len (strlen instrg) );setq (while (< i len) (if (= (substr instrg i 1) " ")(setq j i));found a space (if (= (substr instrg i 1) "/")(setq k i));found a slash (setq i (1+ i)) );while (cond ((and (null j)(null k)) (setq whole instrg)) ((null j) (setq whole (fraction_code instrg))) ( (setq whole (substr instrg 1 (1- j)) fract (fraction_code (substr instrg (1+ j))) whole (strcat whole fract) );setq ) );cond );rtodfrm