AutoLISP: Covert DTEXT & MTEXT to Multileaders

The previous routine only works with MTEXT objects. This routine, however, works with both MTEXT and DTEXT objects and even makes the process easier.

Here’s how:

  • MTLE <enter> to start
  • Select the Text object(s)
  • Specify where the end point (arrow) of the leader should go.


(defun c:mlte (/) (c:MLeaderToExistingtext))
(defun c:MLeaderToExistingtext (/)
(vl-load-com)
  (cond
    ;;Select the text/mtext objects
    ((or
       (null (setq ss1 (ssget ":S" '((0 . "text,mtext")))))
       (= 0 (setq ssl (sslength ss1)))
     )
     nil				;nothing selected
    )
    (T
     (setq
       Textobj	(vlax-ename->vla-object (ssname ss1 0))
       ActSpace	(if (= 0 (getvar "cvport"))
		  (vla-get-paperspace
		    (vla-get-activedocument (vlax-get-acad-object))
		  )
		  (vla-get-modelspace
		    (vla-get-activedocument (vlax-get-acad-object))
		  )
		)
       StartPt	(getpoint "\nPick location for point of arrow head: ")
       txt	(vla-get-TextString Textobj)

       TextPt
		(vla-get-insertionpoint textobj)
       TextPt
		(vlax-variant-value TextPt)
       TextPt
		(vlax-safearray->list TextPt)
       ptlist
		(vlax-make-safearray
		  vlax-vbdouble
		  '(0 . 5)
		)
       ptlist
		(vlax-safearray-fill ptlist (append StartPt TextPt))
       MLObj
		(vla-addmleader
		  ActSpace
		  ptlist
		  'LeaderIndex
		)
     )
     (vla-put-textstring mlobj txt)
     (vla-delete Textobj)

    )
  )
)
Advertisements

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, AutoLISP: Modify, AutoLISP: Text, Leaders, Text. Bookmark the permalink.

8 Responses to AutoLISP: Covert DTEXT & MTEXT to Multileaders

  1. kevgb says:

    Hi Greg
    I keep getting the following error message!

    ; error: no function definition: VLAX-ENAME->VLA-OBJECT

    Kev

    • AutoCAD Tips says:

      Thanks for the heads-up.
      I have updated the code
      The code was missing (vl-load-com)
      This loads the ability for Visual Lisp functions.

      Keep in mind that this is a common issue with code that you may find online. It doesn’t hurt to add this to any routine where you see a warning that mentions VLA-object…

      Thanks

  2. zarko says:

    MTLE to start
    Select the Text object(s) ???

    Finally works with MLTE , command not MTLE !!!!

  3. alex says:

    Can’t use with other ucs.

  4. Pingback: Text to Multileader | AutoCAD Tips

  5. marita says:

    How to do this with multiple text objects, keeping justification, rotation and position? Please help

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s