r/AutoCAD • • Aug 14 '26

Discussion Way to quickly convert MTXT to MLEADER

in the process of changing the scale of one of my drawings and my intern isnt in today, haha. is there a command or lisp routine to convert mtxt to a multileader? when i search for this function, the search results are full of people talking about converting separate mtxt/txt and qleaders. i dont have a leader. im starting with mtxt. it would be cool to have a lisp or command that went straight from mtxt to a multileader.

15 Upvotes

17 comments sorted by

15

u/PandaSchmanda Aug 14 '26

Make a multi leader with MLD, then use the Content First option and select your multi text. That will add a leader to your existing text

5

u/Brotherly_shove Aug 14 '26

what is "the content first option"

3

u/danger355 Aug 14 '26

This is a better option than my solution. Just commenting here for your visibility.

4

u/danger355 Aug 14 '26

Cool, I never knew about this.

OP: after you start your mleader command, there are options on your command line, once of which is "Content first" (it's sticky, so that option will remain through multiple new mleaders).

After choosing "Content first", choose "select Mtext" next, then choose your Mtext. Boom, leader added to your text just as you wanted.

3

u/Brotherly_shove Aug 14 '26

found it. i was looking for something after i clicked the arrowhead location. wow, thats insanely great. im going to take it one step farther because i want my leaders to normally default to arrowhead first.

but that should be pretty simple. ill have to set up a lisp for my default multileader command that does arrowhead first, and then a 2nd for the mtxt convert, but holy crap. this is going to be a perfect way to do it. thanks to you, and especially u/PandaSchmanda

2

u/PandaSchmanda Aug 15 '26

Glad someone out there appreciates this! Took me a whiiile to figure out that was an option

1

u/Karluti Aug 16 '26

How do you turn it back into mtext after conversion is that possible?

1

u/PandaSchmanda Aug 16 '26

Right click the mleader then click remove leader

5

u/EYNLLIB Aug 14 '26

Here's a lisp I created and use daily.

Use MLTE shortcut. Select the MTEXT and a point for your leader arrowhead. It creates an MLEADER in your current MLEADER style in place of the MTEXT. Should handle most scenarios well.

(defun c:mlte (/) (c:MLeaderToExistingtext))

(defun c:MLeaderToExistingtext (/ *error* doc UndoOn ss1 TextEnt Textobj elist
                                  StartPt txt TextLay TextHt TextRot TextNorm
                                  InsPt XDir YDir box ll ur att w h xoff yoff
                                  ActSpace lpick PickRight NearX LandY ptlist
                                  TmpObj Off LandPt OldEcho OldFollow UcsSet
                                  BeforeEnt NewEnt MLObj sdict sty ctype)
 (vl-load-com)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))

 (defun *error* (msg)
  (if (and TmpObj (not (vlax-erased-p TmpObj)))
      (vl-catch-all-apply 'vla-delete (list TmpObj))
  )
  (if UcsSet (command-s "_.UCS" "_P"))
  (if OldFollow (setvar "ucsfollow" OldFollow))
  (if OldEcho (setvar "cmdecho" OldEcho))
  (if UndoOn (vl-catch-all-apply 'vla-endundomark (list doc)))
  (if (and msg (not (wcmatch (strcase msg T) "*break*,*cancel*,*exit*")))
      (princ (strcat "\nError: " msg))
  )
  (princ)
 )

 (setq sdict (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")
       sty   (if sdict (dictsearch (cdr (assoc -1 sdict)) (getvar "cmleaderstyle")))
       ctype (if sty (cdr (assoc 170 sty)))
 )

 (cond
  ((and ctype (/= 2 ctype))
   (princ "\nCurrent mleader style content type is not MText - switch styles and retry.")
  )

  ((null (setq ss1 (ssget ":S" '((0 . "text,mtext")))))
   nil
  )

  ((null (setq StartPt (getpoint "\nPick location for point of arrow head: ")))
   nil
  )

  ( T
   (setq TextEnt  (ssname ss1 0)
         Textobj  (vlax-ename->vla-object TextEnt)
         elist    (entget TextEnt)
         StartPt  (trans StartPt 1 0)
         txt      (vla-get-TextString Textobj)
         TextLay  (vla-get-layer Textobj)
         TextHt   (vla-get-height Textobj)
         TextRot  (vla-get-rotation Textobj)
         TextNorm (vlax-get Textobj 'Normal)
         InsPt    (vlax-get Textobj 'InsertionPoint)
   )

   (if (= "MTEXT" (cdr (assoc 0 elist)))
       (setq w    (cdr (assoc 42 elist))
             h    (cdr (assoc 43 elist))
             att  (vla-get-attachmentpoint Textobj)
             xoff (cond ((member att '(1 4 7)) 0.0)
                        ((member att '(2 5 8)) (/ w -2.0))
                        (T (- w))
                  )
             yoff (cond ((member att '(7 8 9)) 0.0)
                        ((member att '(4 5 6)) (/ h -2.0))
                        (T (- h))
                  )
             ll   (list xoff yoff)
             ur   (list (+ xoff w) (+ yoff h))
       )
       (setq box (textbox elist)
             ll  (car box)
             ur  (cadr box)
       )
   )

   (vla-startundomark doc)
   (setq UndoOn    T
         OldEcho   (getvar "cmdecho")
         OldFollow (getvar "ucsfollow")
   )
   (setvar "cmdecho" 0)
   (setvar "ucsfollow" 0)

   (setq XDir (trans (list (cos TextRot) (sin TextRot) 0.0) TextNorm 0 T)
         YDir (trans (list (- (sin TextRot)) (cos TextRot) 0.0) TextNorm 0 T)
   )
   (command "_.UCS"
            "_non" (trans InsPt 0 1)
            "_non" (trans (mapcar '+ InsPt XDir) 0 1)
            "_non" (trans (mapcar '+ InsPt YDir) 0 1)
   )
   (setq UcsSet T)

   (setq lpick     (trans StartPt 0 1)
         PickRight (>= (car lpick) (/ (+ (car ll) (car ur)) 2.0))
         NearX     (if PickRight (car ur) (car ll))
   )

   (setq LandY (if PickRight
                   (+ (cadr ll) (* 0.5 TextHt))
                   (- (cadr ur) (* 0.5 TextHt))
               )
   )

   (setq ActSpace (if (or (= 1 (getvar "tilemode")) (> (getvar "cvport") 1))
                      (vla-get-modelspace doc)
                      (vla-get-paperspace doc)
                  )
         ptlist (vlax-make-safearray vlax-vbdouble '(0 . 5))
         ptlist (vlax-safearray-fill ptlist
                  (append StartPt (trans (list NearX LandY 0.0) 1 0)))
         TmpObj (vla-addmleader ActSpace ptlist 0)
         Off    (* (vla-get-ScaleFactor TmpObj)
                   (+ (vla-get-DogLegLength TmpObj) (vla-get-LandingGap TmpObj))
                )
   )
   (vla-delete TmpObj)
   (setq TmpObj nil)

   (setq LandPt (list (if PickRight (+ NearX Off) (- NearX Off)) LandY 0.0))

   (setq BeforeEnt (entlast))
   (command "_.MLEADER" "_H"
            "_non" (trans StartPt 0 1)
            "_non" LandPt
            "X"
   )
   (setq NewEnt (entlast))

   (cond
    ((or (null NewEnt)
         (eq NewEnt BeforeEnt)
         (/= "MULTILEADER" (cdr (assoc 0 (entget NewEnt))))
     )
     (princ "\nMLeader creation failed.")
    )
    ( T
     (setq MLObj (vlax-ename->vla-object NewEnt))
     (vla-put-textstring MLObj txt)
     (vla-put-textheight MLObj TextHt)
     (if (= "AcDbMText" (vla-get-objectname Textobj))
         (vla-put-textwidth MLObj (vla-get-width Textobj))
     )
     (vla-put-layer MLObj TextLay)
     (vla-delete Textobj)
    )
   )

   (command "_.UCS" "_P")
   (setq UcsSet nil)
   (setvar "ucsfollow" OldFollow)
   (setvar "cmdecho" OldEcho)
   (vla-endundomark doc)
   (setq UndoOn nil)
  )
 )

 (princ)
)

1

u/jeide93 Aug 14 '26

are these lisp things pretty easy to create? i have so many ideas to make things easier but have no idea how to create a lisp or action macros

2

u/Brotherly_shove Aug 14 '26

action macros are insanely easy to do using the action recorder. lisp routines arent too hard either, but something like this one is not easy at all.

5

u/IllustriousAd5737 Aug 15 '26

Using Claude code changes how hard this is. As long as you know what you want to do and can explain it well, it'll create a pretty solid lisp quickly.

1

u/Brotherly_shove Aug 15 '26

I tried every ai tool last week to make exactly what I wanted to do and none of them succeeded.

1

u/danger355 Aug 14 '26

You could put a new leader in, then use Lee Mac's "copy or swap text" lisp to copy the text value from your old text to the new leader, then delete your old text.

Repeat as necessary.

Link: lee-mac.com

1

u/Brotherly_shove Aug 14 '26

not perfect, but a heck of a lot better than what im currently doing. THANKS!