;;;Change a number in (m)any text string(s) by a numeric value and ;;;specify or change precision (decimal places). ;;;(uses UINT.LSP, USTR.LSP) ;;; ;;;Note: Reduced precision cannot be restored to greater precision ;;; except with UNDO immediately after it has been reduced. ;;; ;;; ;;; ;;;> Author: Henry C. Francis ;;;> 425 N. Ashe St. ;;;> Southern Pines, NC 28387 ;;;> http://paracadd.com ;;;> All rights reserved. ;;; ;;;> COPYRIGHT: 9-19-95 ;;;> EDITED: 08-27-2001 ;;; (DEFUN C:BREAL () ; luprc tele elem tstr cnt_1 cnt_2 pfx_str sfx_str (setq luprc (getvar "luprec")) (setq ndpl (uint 1 "" "Number of decimal places " ndpl)) (setvar "luprec" ndpl) (setq adjv (distof (ustr 1 "\nValue to change number by " (if adjv (rtos adjv) "" ) ;_ end of if nil ) ;_ end of ustr ) ;_ end of distof ) ;_ end of setq (if prevsrch NIL (setq prevsrch '((1 . "*#.###")(1 . "~ELEV=*")(1 . "~*-*")(1 . "~*+*"))) ) ;_ end of if (princ "\nPrevious search pattern: ") (foreach n prevsrch (if (eq (car n) 1) (progn (princ (cdr n)) (princ ", ") ) ;_ end of progn ) ;_ end of if ) ;_ end of foreach (setq srchpatt (list (cons 1 (ustr 1 (strcat "New search pattern for text containing numbers? " (if prevsrch "or

revious or dd to it" "" ) ;_ end of if ) ;_ end of strcat (if prevsrch "Previous" nil ) ;_ end of if T ) ;_ end of ustr ) ;_ end of cons ) ;_ end of list ) ;_ end of setq (if (wcmatch "ADD" (strcase (strcat (cdr (assoc 1 srchpatt)) "*")) ) ;_ end of wcmatch (setq srchpatt (reverse (cdr (reverse (cdr prevsrch))))) ) ;_ end of if (if (wcmatch "PREVIOUS" (strcase (strcat (cdr (assoc 1 srchpatt)) "*")) ) ;_ end of wcmatch (setq srchpatt prevsrch) (while (and (setq addsrch (cons 1 (ustr 0 "Additional selection filter (exact match, wildcards ok, ~ to end input)" (if addsrch (cdr addsrch) nil ) ;_ end of if T ) ;_ end of ustr ) ;_ end of cons ) ;_ end of setq (/= (cdr addsrch) "~") ) ;_ end of and (if (not (member addsrch srchpatt)) (setq srchpatt (append srchpatt (list addsrch) ) ;_ end of append ) ;_ end of setq (princ (strcat "\nSelection filter string " (cdr addsrch) " already specified!" ) ;_ end of strcat ) ;_ end of princ ) ;_ end of if ) ;_ end of while ) ;_ end of if (if (and (> (length srchpatt) 1) (/= (car srchpatt) (cons -4 "")) ) ;_ end of append prevsrch srchpatt ) ;_ end of setq ) ;_ end of if (setq patt_ss (ssget "X" srchpatt)) (if patt_ss (progn (setq psslen (sslength patt_ss) psscnt 0 ) ;_ end of setq (while (< psscnt psslen) ; (setq tele (nentsel "\nSelect number to change ")) (setq elem (entget (ssname patt_ss psscnt))) (setq tstr (cdr (assoc 1 elem))) (setq cnt_1 1 cnt_2 1 ) ;_ end of setq (while (OR (WCMATCH (SUBSTR tstr cnt_1) "#\"*") (WCMATCH (SUBSTR tstr cnt_1) "##\"*") (WCMATCH (SUBSTR tstr cnt_1) "###\"*") (and (/= (substr tstr cnt_1 1) "0") (/= (substr tstr cnt_1 1) "1") (/= (substr tstr cnt_1 1) "2") (/= (substr tstr cnt_1 1) "3") (/= (substr tstr cnt_1 1) "4") (/= (substr tstr cnt_1 1) "5") (/= (substr tstr cnt_1 1) "6") (/= (substr tstr cnt_1 1) "7") (/= (substr tstr cnt_1 1) "8") (/= (substr tstr cnt_1 1) "9") (< cnt_1 (strlen tstr)) ) ;_ end of and ) ;_ end of OR (if (wcmatch (substr tstr cnt_1 5) "%%###") (setq cnt_1 (+ cnt_1 5)) (setq cnt_1 (1+ cnt_1)) ) ;_ end of if ) ;_ end of while (while (or (= (substr tstr (+ cnt_1 cnt_2) 1) "0") (= (substr tstr (+ cnt_1 cnt_2) 1) "1") (= (substr tstr (+ cnt_1 cnt_2) 1) "2") (= (substr tstr (+ cnt_1 cnt_2) 1) "3") (= (substr tstr (+ cnt_1 cnt_2) 1) "4") (= (substr tstr (+ cnt_1 cnt_2) 1) "5") (= (substr tstr (+ cnt_1 cnt_2) 1) "6") (= (substr tstr (+ cnt_1 cnt_2) 1) "7") (= (substr tstr (+ cnt_1 cnt_2) 1) "8") (= (substr tstr (+ cnt_1 cnt_2) 1) "9") (and (= (substr tstr (+ cnt_1 cnt_2) 1) ".") (not (= (strlen tstr) (+ cnt_1 cnt_2))) ) ;_ end of and ) ;_ end of or (setq cnt_2 (1+ cnt_2)) ) ;_ end of while (if (> cnt_1 1) (progn (setq pfx_str (substr tstr 1 (1- cnt_1))) (if (>= (strlen tstr) (+ cnt_1 cnt_2)) (setq sfx_str (substr tstr (+ cnt_1 cnt_2))) (setq sfx_str "") ) ;_ end of if ) ;_ end of progn (progn (if (>= (strlen tstr) (1+ cnt_2)) (setq sfx_str (substr tstr (1+ cnt_2))) (setq sfx_str "") ) ;_ end of if (setq pfx_str "") ) ;_ end of progn ) ;_ end of if (setq nstr (strcat pfx_str (if (and (eq pfx_str "") (eq sfx_str "")) (rtos (+ (distof tstr 2) adjv) 2 ndpl) (rtos (+ (distof (substr tstr cnt_1 cnt_2) 2) adjv) 2 ndpl) ) ;_ end of if sfx_str ) ;_ end of strcat ) ;_ end of setq (if (eq tstr nstr) (progn (setq upd_thsno "No") (princ (strcat "\nReplacement string is the same, no change to " tstr ) ;_ end of strcat ) ;_ end of princ ) ;_ end of progn (setq upd_thsno (ukword 1 "Yes No" (strcat "Replace \"" tstr "\" with \"" nstr "\"?") "Yes" ) ;_ end of ukword ) ;_ end of setq ) ;_ end of if (if (eq upd_thsno "Yes") (progn (setq elem (subst (cons 1 nstr) (assoc 1 elem) elem ) ;_ end of subst ) ;_ end of setq ) ;_ end of progn ) ;_ end of if (entmod elem) (entupd (cdr (assoc -1 elem))) (setq psscnt (1+ psscnt)) ) ;_ end of while ) ;_ end of progn (princ (strcat "\nNo text found containing numbers matching " (cdr (assoc 1 srchpatt)) "!" ) ;_ end of strcat ) ;_ end of princ ) ;_ end of if (setvar "luprec" luprc) (princ) ) ;_ end of DEFUN ;|«Visual LISP© Format Options» (72 2 40 2 T "end of " 60 9 0 0 0 T T nil T) ***Don't add text below the comment!***|;