Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
bodhran
Posts: 69
Registered: ‎10-14-2010
Message 1 of 2 (506 Views)

Convert single Dtext to Single MText

506 Views, 1 Replies
12-02-2010 07:04 PM

 

 

Hi guys,

 

We're looking for a routine to convert multiple Dtext text objects to Mtext object. The problem we are having is that when we run txt2mtxt over our dtext in AutoCAD 2011 the dtext is converted to mtext but all in one mtext object.

 

We are actually trying to text mask multiple dtexts but they seem to be deleted when the mask is created. so something that can achieve that would also be a solution.

 

Regards,

 

B

*Expert Elite*
pbejse
Posts: 2,511
Registered: ‎11-24-2009
Message 2 of 2 (494 Views)

Re: Convert single Dtext to Single MText

12-02-2010 08:47 PM in reply to: bodhran

You can select multiple objects and process them one at a time

 

Try something like this

 

<Untested>

(defun c:test (/ text_objects cnt)
  	(setq text_objects (ssget '((0 . "TEXT"))) cnt -1)
		(while (setq e (ssname text_objects (setq cnt (1+ cnt))))
		  	(setq ent_to (entget e)
			      typ    (cdr (assoc 0 ent_to))
			      pt     (cdr (assoc 10 ent_to))
			      str    (cdr (assoc 1 ent_to))
			      ht     (cdr (assoc 40 ent_to))
			      rt     (cdr (assoc 50 ent_to))
			      jt     (cdr (assoc 71 ent_to))
			      sst    (cdr (assoc 7 ent_to))
			)
		(entdel e)
  		(PBE:MText pt str ht rt sst)
		  		  )
	       )
(defun PBE:MText (pt str ht rt sst / Txt_created)
  (setq Txt_created
  (entmakex (list (cons 0 "MTEXT")
		  (cons 100 "AcDbEntity")
		  (cons 100 "AcDbMText")
		  (cons 10 pt)
		  (cons 1 str)
		  (cons 40 ht)
		  (cons 50 rt)
		  (cons 71 jt)
		  (cons 7 sst)
		  '(90 . 1)
		  '(63 . 1)
		 '(441 . 3935927);<---- this is index color red
	    )
  )
	)
  (if Txt_created
    (progn
      (setq nct	    (entlast)
	    ent_mod (entget nct)
      )
      (entmod (subst (cons 71 7) (assoc 71 ent_mod) ent_mod))
    )
  )(princ)
)

 

it will convert the text to mtext and mask it RED (color index).. change it to whatever color you want

I suggest you add prompt for color if you have to :-)

 

Now if you need true color you have to add DXF 421

In case you're wondering what the entmod is for.. notice when you use txt2mtxt commnad the position of the text is shifted. that line will move it to where it was before (at leat in theory)

 

hope this helps

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.