Please advise a lisp to replace part of mtext (with 3 lines) with out prompt. MTEXT shown below
DATE: 28.05.2012
TEL NO: 04 2541131131
FAX NO : 04 5451212312
TeL no only want to replace with other pre defined no.
Please help
anoop
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Solved by p_mcknight. Go to Solution.
What is your way of selecting the text to change? Will the user select it or do you want to change all such text objects in the drawing? However you select the text, once you make a vla-object out of it, it is easy to change the text value via
(vla-put-TextString "DATE: 28.05.2012\nTEL NO: 04 2541131131\nFAX NO : 04 5451212312")
Perhaps something like this.
Change the xx xxxxxxxxxx to the new number.
(defun c:test (/ ENT ENTD I SS STR) (if (setq ss "_X" (ssget '((0 . "MTEXT"))) ) (repeat (setq i (sslength ss)) (setq ent (entget (ssname ss (setq i (1- i)))) str (cdr (assoc 1 ent)) ) (if (wcmatch str "*TEL NO: 04 2541131131*") (progn (setq str (vl-string-subst "TEL NO: xx xxxxxxxxxx" "TEL NO: 04 2541131131" str ) ) (setq ent (subst (cons 1 str) (assoc 1 ent) ent)) (entmod ent) ) ) ) ) (princ) )
HTH
Henrique
Thank for you effort, but its not working, showing below message. Can u chek in my attached drawing
Command: test
Unknown command "TEST". Press F1 for help.
Command: 'VLIDE too few arguments in SETQ: (SETQ SS "_X" (SSGET (QUOTE ((0 .
"MTEXT")))))
Command:
Command: test
Unknown command "TEST". Press F1 for help.
Try
(defun c:test21 ( / ent vlobj textString )
(setq ent (entnext))
(while ent
(setq vlobj (vlax-ename->vla-object ent))
(if (= "AcDbMText" (vla-get-objectname vlobj))
(progn
(setq textString (vla-get-textstring vlobj))
(terpri)(princ textString)(terpri)
(if (and (vl-string-search "DATE" textString) (vl-string-search "TEL NO" textString) (vl-string-search "FAX NO" textString))
(vla-put-textString vlobj "DATE:xxxx\nTEL NO:xxxxxx\nFAX NOxxxxxxx")
)
)
)
(setq ent (entnext ent))
)
(princ)
)
The font type doesn't change on mine. If you mean the actual text, change the string I put in the LISP to whatever string you would like. Otherwise, repost you document after the font has changed so I can take a look.
Sorry, my code have a typo...
Try this one
(defun c:test (/ ENT ENTD I SS STR) (if (setq ss (ssget "_X" '((0 . "MTEXT")))) (repeat (setq i (sslength ss)) (setq ent (entget (ssname ss (setq i (1- i)))) str (cdr (assoc 1 ent)) ) (if (wcmatch str "*2541131131*") (progn (setq str (vl-string-subst "xxxxxxxxxx" "2541131131" str ) ) (setq ent (subst (cons 1 str) (assoc 1 ent) ent)) (entmod ent) ) ) ) ) (princ) )
HTH
Henrique