I currently have this code modified by gileCAD and I myself tried modifying. But I currently wanted to also grab the source text's text height as well when replacing other text but with the code below, I get an error of "Program ERROR: bad DXF group: 50.0".
(defun c:MTP (/ cEnt elst text color ss i textSize)
(if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
(member (cdr (assoc 0 (entget cEnt)))
'("TEXT" "MTEXT" "ATTRIB")
)
1)
(progn
(setq elst (entget cEnt)
text (assoc 1 elst)
color (cond ((assoc 62 elst))
(T '(62 . 256))
)
textSize (cdr (assoc 40 elst)) ; get text size
)
(redraw cEnt 3)
(if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
(repeat (setq i (sslength ss))
(setq elst (entget (ssname ss (setq i (1- i)))))
(entmod
(subst text
(assoc 1 elst)
(if (assoc 62 elst)
(entmod (subst color (assoc 62 elst) elst))
(append elst (list color))
)
(entmod (subst textSize (assoc 40 elst) elst))
(append elst (list textSize))
)
)
)
)
)
)
(command "_regenall")
(princ)
)
Modified code from CAD Developer: It doesn't have any error and it does use the source text's text height and text color but doesn't replace the select text/mtext that matches the content of the source text.
(defun c:MTP (/ cEnt elst text color ss i textSize)
(if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
(member (cdr (assoc 0 (entget cEnt)))
'("TEXT" "MTEXT" "ATTRIB")
)
1)
(progn
(setq elst (entget cEnt)
text (assoc 1 elst)
color (cond ((assoc 62 elst))
(T '(62 . 256))
)
textSize (cdr (assoc 40 elst)) ; get text size
)
(redraw cEnt 3)
(if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
(repeat (setq i (sslength ss))
(setq elst (entget (ssname ss (setq i (1- i)))))
(entmod
(subst text
(assoc 1 elst)
(if (assoc 62 elst)
(entmod (subst color (assoc 62 elst) elst))
(append elst (list color))
)
)
)
(entmod
(if (assoc 40 elst)
(subst (cons 40 textSize) (assoc 40 elst) elst)
(append elst (list (cons 40 textSize)))
)
)
)
)
)
)
(command "_regenall")
(princ)
)
Text height is code 40
(defun c:MTP (/ cEnt elst text color ss i textSize)
(if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
(member (cdr (assoc 0 (entget cEnt)))
'("TEXT" "MTEXT" "ATTRIB")
)
1)
(progn
(setq elst (entget cEnt)
text (cdr(assoc 1 elst))
color (if (assoc 62 elst)
(cdr (assoc 62 elst) )
256
)
textSize (cdr (assoc 40 elst)) ; get text size
)
(redraw cEnt 3)
(if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
(repeat (setq i (sslength ss))
(setq DXEntity(ssname ss (setq i (1- i))) )
(DXF:Put DXEntity 1 text)
(DXF:Put DXEntity 40 textSize)
(DXF:Put DXEntity 62 color)
)
)
)
)
(command "_regenall")
(princ)
)
( defun DXF:Put( DXEntity code newValue / elst ) ; (setq code 1) (setq newValue "test")
(setq elst (entget DXEntity))
(entmod
(if (assoc code elst)
(subst (cons code newValue) (assoc code elst) elst)
(append elst (list (cons code newValue)))
)
)
)