Mtedit AutoLISP routine to change mtext in 100 drawings

Mtedit AutoLISP routine to change mtext in 100 drawings

Slawomir_
Advisor Advisor
1,597 Views
7 Replies
Message 1 of 8

Mtedit AutoLISP routine to change mtext in 100 drawings

Slawomir_
Advisor
Advisor

Hi!

 

I'm trying to figure out how to change mtext in 100 drawings. It is the same, in the same place and the change is the same in every drawing. Now I have "First line" and I want to have "First Row/Second Row" in two rows. I wrote simple AutoLISP routine to execute it automatically. Its working only to the moment of picking up certain mtext. Don't know what to do next, what to write to put "First Row/Second Row" sentnece in mtext.

 

If you have some advice I will be very happy.


AutoLISP code:

 

(defun c:mtextchange (/ pt11)
  (setq pt11 '(221 49))
  (command "._mtedit" pt11 "Firs Row Second Row") ;don't know what to write here, how should correct syntax looks like.
  (princ)
)

0 Likes
Accepted solutions (1)
1,598 Views
7 Replies
Replies (7)
Message 2 of 8

wispoxy
Advisor
Advisor

Just use the Find / Replace. Command FIND

0 Likes
Message 3 of 8

Slawomir_
Advisor
Advisor

FIND command could be useful too, I will try it.

 

But problem is: 100 drawings and one change per one drawing. I'm trying to write AutoLISP routine that will do the work alongside with script (*.scr) file and bat file (*.bat). Bat and script is working. Now I'm investigating entsel and entget functions.

0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

THIS Lee Mac's Batch Replace routine will not help?

 

 

Message 5 of 8

wispoxy
Advisor
Advisor
When you say 'drawing' are you talking about layouts or files?
0 Likes
Message 6 of 8

Slawomir_
Advisor
Advisor

I'm talking about houndred dwg files and mtext is placed in layout. Every drawing have only one layout.

0 Likes
Message 7 of 8

ВeekeeCZ
Consultant
Consultant

@leonsj.s wrote:

Hi!

 

I'm trying to figure out how to change mtext in 100 drawings. It is the same, in the same place and the change is the same in every drawing. Now I have "First line" and I want to have "First Row/Second Row" in two rows. I wrote simple AutoLISP routine to execute it automatically. Its working only to the moment of picking up certain mtext. Don't know what to do next, what to write to put "First Row/Second Row" sentnece in mtext.

 

If you have some advice I will be very happy.


AutoLISP code:

 

(defun c:mtextchange (/ pt11)
  (setq pt11 '(221 49))
  (command "._mtedit" pt11 "Firs Row Second Row") ;don't know what to write here, how should correct syntax looks like.
  (princ)
)


Even I think Lee Mac's solution could be better (see above, I didn't try), you can try this code as well.

 

Paragraph separater: \\P

 

(defun MtextReplace (find replace / ss i ed)
  (if (setq ss (ssget "_X" '((0 . "MTEXT"))))
    (repeat (setq i (sslength ss))
      (if (= (cdr (assoc 1 (setq ed (entget (ssname ss (setq i (1- i))))))) find)
	(entmod (subst (cons 1 replace)
		       (assoc 1 ed)
		       ed)))))
)

(defun c:Test nil (MtextReplace "First line" "First line\\PSecond line") (princ))

 

or this one... searching by given 10 point

 

Spoiler
(defun MtextPtReplace (pt replace / ss i ed)

    (if (setq ss (ssget "_X" '((0 . "MTEXT"))))
    (repeat (setq i (sslength ss))
      (if (equal (cdr (assoc 10 (setq ed (entget (ssname ss (setq i (1- i)))))))
		 pt
		 0.5)
	(entmod (subst (cons 1 replace)
		       (assoc 1 ed)
		       ed)))))
)

(defun c:test2 nil (MtextPtReplace '(1132.02 882.088 0.0) "First line\\PSecond line") (princ))

 

0 Likes
Message 8 of 8

Slawomir_
Advisor
Advisor

BeekeeCZ napisali:

THIS Lee Mac's Batch Replace routine will not help?

 

 


Hi BeekeeCZ, link doesn't work, I assume that You mean Batch Find & Replace Text (BFindV2-0.lsp) from Lee Mac website. Correct me if I'm wrong.

0 Likes