Jump to content

text to mtext lisp without the text moving?


Organic

Recommended Posts

I have long used the following lisp to convert multiple single text objects into multiple mtext objects (i.e. make each text entity into separate mtext entities).

 

; T2M - convert individual Texts/Dtexts to individual MTexts
; modified by Xanadu - www.xanadu.cz
;
(defun C:T2M (/ ss i elist)
 (prompt "\nSelect Text objects to convert to MTexts: ")
 (setq ss (ssget (list (cons 0 "TEXT"))))
 (setq i -1)
 (if ss
   (repeat (sslength ss)
     (setq elist (cdr (assoc -1 (entget (ssname ss (setq i (1+ i)))))))
     (command "TXT2MTXT" elist ""); Express Tools command
   )
 )

However, the mtext entity always moves position slightly (compared to the original text entity) after converting the object. Is there a way to fix this or does anyone have a better lisp that converts multiple text entities into mtext entities (which are all separate still, i.e. not joined together) without the position of the entity changing? Cheers

Link to comment
Share on other sites

This modified one I found seems to work better, although still moves it slightly.

 

(defun c:t2m (/ sset count num en el mcontent bbox point1 point2 point3 point4 mwidth mheight mstyle njust mrotate nmtext)
   (setvar "cmdecho" 0)
   (setq sset (ai_aselect))
   (if (null sset)
       (progn
           (princ "\nNo objects selected.")
           (exit)
       )
   )
   (setq count 0)
   (while (/= (ssname sset COUNT) nil)
       (setq EN (ssname sset COUNT))
       (setq EL (entget EN))
       (if (= (cdr (assoc 0 EL)) "TEXT")
           (progn
               (setq mcontent (cons '1 (strcase (cdr (assoc 1 el)))))
               (setq curlay (cdr (assoc 8 el)))
               (setq bbox (acet-geom-textbox EL 0.1))
               (setq point1 (car bbox))
               (setq point2 (cadr bbox))
               (setq point3 (cadr (cdr bbox)))
               (setq point4 (cadr (cdr (cdr bbox))))
               (setq mwidth (cons '41 (distance point1 point2)))
               (setq mheight (cons '40 (cdr (assoc 40 el))))
               (setq mstyle (cons '7 (cdr (assoc 7 el))))
               (setq nspace (cons '410 (cdr (assoc 410 EL))))
               (setq minsert (cons '10 (cdr (assoc 10 EL))))
               (cond
                   ((and (= (cdr (assoc 72 el)) 0)(= (cdr (assoc 73 el)) 3))(setq NJUST (cons '71 1)));JY
                   ((and (= (cdr (assoc 72 el)) 1)(= (cdr (assoc 73 el)) 3))(setq NJUST (cons '71 2)));JU
                   ((and (= (cdr (assoc 72 el)) 2)(= (cdr (assoc 73 el)) 3))(setq NJUST (cons '71 3)));JI
                   ((and (= (cdr (assoc 72 el)) 0)(= (cdr (assoc 73 el)) 2))(setq NJUST (cons '71 7)));JN
                   ((and (= (cdr (assoc 72 el)) 1)(= (cdr (assoc 73 el)) 2))(setq NJUST (cons '71 7)));JN
                   ((and (= (cdr (assoc 72 el)) 2)(= (cdr (assoc 73 el)) 2))(setq NJUST (cons '71 6)));JK
                   ((and (= (cdr (assoc 72 el)) 0)(= (cdr (assoc 73 el)) 0))(setq NJUST (cons '71 7)));JN
                   ((and (= (cdr (assoc 72 el)) 4)(= (cdr (assoc 73 el)) 0))(setq NJUST (cons '71 7)));JN
                   ((and (= (cdr (assoc 72 el)) 0)(= (cdr (assoc 73 el)) 1))(setq NJUST (cons '71 7)));JN
                   ((and (= (cdr (assoc 72 el)) 1)(= (cdr (assoc 73 el)) 0))(setq NJUST (cons '71 7)));JN
                   ((and (= (cdr (assoc 72 el)) 1)(= (cdr (assoc 73 el)) 1))(setq NJUST (cons '71 ));JM
                   ((and (= (cdr (assoc 72 el)) 2)(= (cdr (assoc 73 el)) 1))(setq NJUST (cons '71 9)));J,
                   ((and (= (cdr (assoc 72 el)) 2)(= (cdr (assoc 73 el)) 0))(setq NJUST (cons '71 7)));JN
               )
               (setq mrotate (cons '50 (cdr (assoc 50 el))))
               (setq nmtext (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(67 . 0) nspace (cons 8 curlay) '(100 . "AcDbMText") minsert njust mheight mwidth mstyle mcontent mrotate))
               (entmake nmtext)
               (entdel en)
               (setq count (+ count 1))
           )
           (setq count (+ count 1))
       )
   )
   (setvar "cmdecho" 1)(princ)
)

Link to comment
Share on other sites

I've just tried that 2nd lisp code but it doesn't seem to work for me... any ideas why?

 

Command: T2M

Select objects: Specify opposite corner: 5 found

Select objects:

; error: bad DXF group: nil

Command:

 

When I go back into the appload dialogue box the command is ghosted and I'm unable to select it to unload, what does this mean?

 

As for the first code you quoted, what is the line about Express Tools TXT2MTXT? Does the lisp replace the ET command?

 

Any help appreciated because I've been wanting a multiple text to mtext converter for some time.

Link to comment
Share on other sites

I've just tried that 2nd lisp code but it doesn't seem to work for me... any ideas why?

 

 

 

When I go back into the appload dialogue box the command is ghosted and I'm unable to select it to unload, what does this mean?

 

As for the first code you quoted, what is the line about Express Tools TXT2MTXT? Does the lisp replace the ET command?

 

Any help appreciated because I've been wanting a multiple text to mtext converter for some time.

 

They both work for me in AutoCad 2014.

 

I'm not exactly sure although I think it just uses that command to convert it.

 

If anyone has any better lisp that reduces further or eliminates the movement when converting, please do share.

Link to comment
Share on other sites

  • 1 year later...

Hi Organic,

 

Did anyone ever have any luck with this one? I use the above T2M LISP quite frequently but am very interested in finding one that doesn't move text/change the basepoint.

Link to comment
Share on other sites

  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...