Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp required to replace part of mtext with out prompt

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
anoopvarrghese009
815 Views, 11 Replies

Lisp required to replace part of mtext with out prompt

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

11 REPLIES 11
Message 2 of 12

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")

Message 3 of 12

Thanks for reply. I want change all text in drawing.
Message 4 of 12
hmsilva
in reply to: anoopvarrghese009

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

EESignature

Message 5 of 12
anoopvarrghese009
in reply to: hmsilva

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.

Message 6 of 12

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)
  )

Message 7 of 12

thank you its working, font is getting changed can you add that also?

anoop
Message 8 of 12

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.

Message 9 of 12
hmsilva
in reply to: anoopvarrghese009

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

EESignature

Message 10 of 12
anoopvarrghese009
in reply to: hmsilva

Thank you

Message 11 of 12

thank you

Message 12 of 12
hmsilva
in reply to: anoopvarrghese009

You're welcome!
Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost