;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; by muwind
- (defun getdimtext(ent / e el roop dim_text)
- (if ent
- (progn
- (setq e (cdr (assoc -2 (tblsearch "block" (cdr (assoc 2 (entget ent )))))) roop T)
- (while roop
- (setq el (entget e ))
- (setq e (entnext e ))
- (if (member ( cons 0 "MTEXT") el)
- (setq roop nil)
- );end if
- );end while
- (if (or (wcmatch (cdr (assoc 1 (entget ent))) "*<>*,*<>,<>*")
- (= (cdr (assoc 1 (entget ent))) "" ))
- (if (wcmatch (cdr (assoc 1 el )) "\\A1;*")
- ( setq dim_text (substr (cdr (assoc 1 el )) 5))
- ( setq dim_text (cdr (assoc 1 el )))
- );end if
- (cdr (assoc 1 (entget ent)))
- );end if
- );end progn
- );end if
- )
- ;;; 修改 by HLCAD at 2021-1-9.
- (defun C:tt (/ p l n e en os as ns st s sn nsl osl sl si chf chm)
- (setq chm 0)
- (if (setq p (ssget "x" '((0 . "*TEXT,DIM*")))) ; Select objects
- ; (if (setq p (ssget '((0 . "*TEXT,DIM*")))) ; Select objects
- (progn ; If any objects selected
- (while (= (setq osl (strlen (setq os (getstring "\nOriginal text: " t)))) 0)
- (princ "Null input invalid")
- )
- (setq nsl (strlen (setq ns (getstring "\nTarget text: " t))))
- (setq l 0 n (sslength p))
- (while (< l n) ; For each selected object...
- (if (and (setq sn (cdr (assoc 0 (setq e (entget (setq en (ssname p l)))))))
- (member sn '("MTEXT" "TEXT" "DIMENSION")); Look for TEXT entity type (group 0)
- )
- (progn
- (setq chf nil si 1)
- (if (= sn "DIMENSION")
- (setq s (getdimtext en) as (assoc 1 e))
- (setq s (cdr (setq as (assoc 1 e))))
- )
- (while (= osl (setq sl (strlen (setq st (substr s si osl)))))
- (if (= st os)
- (progn
- (setq s (strcat (substr s 1 (1- si)) ns (substr s (+ si osl))))
- (setq chf t) ; Found old string
-
- (setq si (+ si nsl))
- )
- (setq si (1+ si))
- )
- )
- (if chf
- (progn ; Substitute new string for old
- (setq e (subst (cons 1 s) as e))
- (entmod e) ; Modify the TEXT entity
-
- (setq chm (1+ chm))
- ))
- )
- )
- (setq l (1+ l))
- )
- ))
- (princ (strcat "edited " (itoa chm) " lines of text." )) ; Print total lines changed
- (princ)
- )
|