Visual LISP, AutoLISP and General Customization

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

Convert single Dtext to Single MText

502 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.





*Expert Elite*
Posts: 2,441
Registered: ‎11-24-2009
Message 2 of 2 (490 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



(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
      (setq nct	    (entlast)
	    ent_mod (entget nct)
      (entmod (subst (cons 71 7) (assoc 71 ent_mod) ent_mod))


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



You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community