First off, Ronjonp, I have to say, awesome code, I have had a routine that convert leaders with mtext, but quite often the details that I have been converting didn't even use mtext on the leaders, so this has been a huge help.
I have modified the code to be able to convert the line from the leader as well, it is not perfect at getting the insertion points right, but it is close and I am sure that there are plenty of improvements that can be made:
; Modified from original code posted by ronjonp at http://www.theswamp.org/index.php?topic=30914.0
; Modifications made by cmwade77 at http://www.theswamp.org
(defun c:l2m ()
(vl-load-com)
(defun rjp-getbbwdth (obj / out ll ur)
(vla-getboundingbox obj 'll 'ur)
(setq out (mapcar 'vlax-safearray->list (list ll ur)))
(distance (car out) (list (caadr out) (cadar out)))
)
(princ "\nSelect items to convert to mleader: ")
(setq items (ssget))
(setq a 0)
(setq ss (ssadd))
(setq ss2 (ssadd))
(while (< a (sslength items))
(progn
(setq EA (entget (ssname items a)))
(setq EC (cdr (assoc 0 EA)))
(if (and (/= EC nil) (/= EC null) (/= EC ""))
(progn
(if (WCMATCH EC "*TEXT")
(ssadd (ssname items a) ss)
(ssadd (ssname items a) ss2)
)
)
)
(setq a (+ a 1))
)
)
(if (= (sslength ss2) 1)
(progn
(setq leader2 (entget (ssname ss2 0)))
)
(progn
(setq leader (entsel "\nInvalid Leader Selected\nPick Leader: ")
leader2(entget (car leader)))
)
)
(setq
pt1 (dxf 10 leader2) ; get first point of leader
)
(vl-cmdf "._ERASE" ss2 "")
(if (> (sslength ss) 0)
(progn
(setq EE (entget (ssname ss (- (sslength ss) 1))))
(setq pt2 (cdr (assoc 10 EE)))
(setq txt (apply
'strcat
(mapcar
'cdr
(vl-sort
(mapcar '(lambda (x)
(cons (vlax-get x 'insertionpoint)
(strcat (vlax-get x 'textstring) " ")
)
)
(setq
ss (mapcar
'vlax-ename->vla-object
(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
)
)
)
(function (lambda (y1 y2) (< (cadr (car y2)) (cadr (car y1))))
)
)
)
)
w (car (vl-sort (mapcar 'rjp-getbbwdth ss) '>))
txt (apply 'strcat
(mapcar 'chr (reverse (cdr (reverse (vl-string->list txt)))))
)
)
(mapcar 'vla-delete ss)
)
)
(progn
(command "._MLEADER" pt1 pt2 "")
(setq newleader (vlax-ename->vla-object (entlast)))
(vla-put-textstring newleader txt)
(vla-put-textwidth newleader w)
)
)
I normally will use this command on each leader that I need to convert, then use the mleader align command to get everything lined up the way I want.
I changed the command to L2M as well, as it modifies the way the old one functions, so I want to make sure that I don't step on anyone's toes. All you need to do is select the leader line at the same time that you select the text to convert. I hope it works for you as well as it does for me.
Feel free to modify this code, just make sure that credit is given as appropriate.