Modify lisp for dtext to mtext

Discussion in 'AutoCAD' started by John Crocco, Mar 3, 2004.

  1. John Crocco

    John Crocco Guest

    Below is a lisp that works as is to turn dtext into mtext. This routine
    requires the pick of at least two dtext objects to turn them into mtext.
    Can this be modified to change just one line of dtext into mtext. I would
    like it to be one routine able to do either option, turn one line of dtext
    to mtext, or multi lines of dtext to mtext.

    I dont remember who wrote it or where I got it from (somewhere on this
    newsgroup a few years ago) but I am sure others could also benefit from it
    as well.

    lisp name is TXT2MTXT.lsp

    (defun col2str (inp)
    (cond
    ((= inp nil)(setq ret "BYLAYER"))
    ((= inp 256)(setq ret "BYLAYER"))
    ((= inp 0)(setq ret "BYBLOCK"))
    ((and (> inp 0)(< inp 255))(setq ret (itoa inp)))
    (t nil)
    )
    )

    (defun savprop ()
    (setq clayer (getvar "CLAYER"))
    (setq cecolor (getvar "CECOLOR"))
    (setvar "CECOLOR" "BYLAYER")
    (setq celtype (getvar "CELTYPE"))
    (setvar "CELTYPE" "BYLAYER")
    (setq thickness (getvar "THICKNESS"))
    (setvar "THICKNESS" 0)
    (if (>= (atoi (getvar "ACADVER")) 13)
    (progn
    (setq celtscale (getvar "CELTSCALE"))
    (setvar "CELTSCALE" 1.0)
    )
    )
    )

    (defun resprop ()
    (if (>= (atoi (getvar "ACADVER")) 13)
    (setvar "CELTSCALE" celtscale)
    )
    (setvar "THICKNESS" thickness)
    (setvar "CELTYPE" celtype)
    (setvar "CECOLOR" cecolor)
    (setvar "CLAYER" clayer)
    )

    (defun textrect (tent / ang sinrot cosrot t1 t2 p1 p2 p3 p4)
    (setq p0 (cdr (assoc 10 tent))
    ang (cdr (assoc 50 tent))
    sinrot (sin ang)
    cosrot (cos ang)
    t1 (car (textbox tent))
    t2 (cadr (textbox tent))
    p1 (list (+ (car p0)
    (- (* (car t1) cosrot) (* (cadr t1) sinrot)))
    (+ (cadr p0)
    (+ (* (car t1) sinrot) (* (cadr t1) cosrot))))
    p2 (list (+ (car p0)
    (- (* (car t2) cosrot) (* (cadr t1) sinrot)))
    (+ (cadr p0)
    (+ (* (car t2) sinrot) (* (cadr t1) cosrot))))
    p3 (list (+ (car p0)
    (- (* (car t2) cosrot) (* (cadr t2) sinrot)))
    (+ (cadr p0)
    (+ (* (car t2) sinrot) (* (cadr t2) cosrot))))
    p4 (list (+ (car p0)
    (- (* (car t1) cosrot) (* (cadr t2) sinrot)))
    (+ (cadr p0)
    (+ (* (car t1) sinrot) (* (cadr t2) cosrot))))
    )
    (list p1 p2 p3 p4)
    )

    (defun C:TXT2MTXT ( / mwid dset ibrk bitm bent sset rect mlay mcol mlst
    bins bang tang nins num ndis chnd cent nhnd nstr
    str pt1 pt2 pt3 dis dvx dvy dvz new)
    (if (< (atoi (getvar "ACADVER")) 13)
    (alert "This Function Requires\nRelease 13 or Higher")
    (progn
    (setq cmdecho (getvar "CMDECHO"))
    (setvar "CMDECHO" 0)
    (command "_.UNDO" "_G")
    (setq mwid 0.0)
    (setq dset (ssadd))
    ;
    (initget "Y N")
    (setq tmp (getkword "\nDS> Include Line Breaks <Y>/N: "))
    (if (/= tmp "N")(setq ibrk "Y")(setq ibrk "N"))
    ;
    (setq bitm (car (entsel "\nDS> Pick Base String: ")))
    (setq bent (entget bitm))
    (setq rect (textrect bent))
    (setq chk (distance (car rect)(cadr rect)))
    (if (> chk mwid)(setq mwid chk))
    ;
    (if (= "TEXT" (cdr (assoc 0 bent)))
    (progn
    (redraw bitm 3)
    (princ "\nDS> Select Remaining Text: ")
    (setq sset (ssget '((0 . "TEXT"))))
    (if sset
    (progn
    (setq rect (textrect bent))
    (setq orig rect)
    (setq mlay (cdr (assoc 8 bent)))
    (setq mcol (cdr (assoc 62 bent)))
    (setq mlst (list (cdr (assoc 1 bent))))
    ;
    (if (> (cdr (assoc 72 bent)) 0)
    (setq bins (cdr (assoc 11 bent)))
    (setq bins (cdr (assoc 10 bent)))
    )
    (setq bang (cdr (assoc 50 bent)))
    (setq tang (- bang (/ PI 2)))
    (setq nins bins)
    (ssdel bitm sset)
    (while (> (sslength sset) 0)
    (setq num (sslength sset) itm 0)
    (setq ndis 99999999.9)
    (while (< itm num)
    (setq chnd (ssname sset itm))
    (setq cent (entget chnd))
    (if (> (cdr (assoc 72 cent)) 0)
    (setq cins (cdr (assoc 11 cent)))
    (setq cins (cdr (assoc 10 cent)))
    )
    (setq cdis (distance bins cins))
    (if (< cdis ndis)
    (setq ndis cdis nhnd chnd nent cent)
    )
    (setq itm (1+ itm))
    )
    (setq dset (ssadd nhnd dset))
    (ssdel nhnd sset)
    ;
    (setq rect (textrect nent))
    (setq chk (distance (car rect)(cadr rect)))
    (if (> chk mwid)(setq mwid chk))
    ;
    (setq nstr (cdr (assoc 1 nent)))
    (setq mlst (append mlst (list nstr)))
    )
    ;
    (entdel bitm)
    (setq num (sslength dset) itm 0)
    (while (< itm num)
    (setq hnd (ssname dset itm))
    (entdel hnd)
    (setq itm (1+ itm))
    )
    ;
    (savprop)
    (setvar "CLAYER" mlay)
    (if (/= mcol nil)
    (setvar "CECOLOR" (col2str mcol))
    )
    (setq mwid (+ mwid (* mwid 0.025)))
    (setq pt1 (car orig))
    (setq pt2 (cadr orig))
    (setq dis (distance pt1 pt2))
    (setq dvx (/ (- (car pt2)(car pt1)) dis))
    (setq dvy (/ (- (cadr pt2)(cadr pt1)) dis))
    (setq pt3 (list dvx dvy 0.0))
    (setq nins (list (car (cadddr orig))
    (cadr (cadddr orig))
    (nth 2 (cdr (assoc 10 bent)))))
    ;
    (setq new '((0 . "MTEXT")(100 . "AcDbEntity")(100 .
    "AcDbMText")))
    (setq new (append new (list (assoc 7 bent))))
    (setq new (append new (list (assoc 8 bent))))
    (setq new (append new (list (cons 10 nins))))
    (setq new (append new (list (cons 11 pt3))))
    (foreach lin mlst
    (if (= ibrk "Y")
    (if (/= lin (last mlst))
    (setq lin (strcat lin "\\P"))
    )
    (setq lin (strcat lin " "))
    )
    (setq new (append new (list (cons 1 lin))))
    )
    (setq new (append new (list (assoc 40 bent))))
    (setq new (append new (list (cons 41 mwid))))
    (setq new (append new (list (cons 71 1))))
    (setq new (append new (list (cons 72 1))))
    (entmake new)
    (resprop)
    ;
    (setq sset nil)
    (setq dset nil)
    (setq lst nil)
    (command "_.UNDO" "_E")
    (setvar "CMDECHO" cmdecho)
    )
    (redraw bitm 4)
    )
    )
    )
    )
    )
    (setq sset nil)
    (setq mlst nil)
    (princ)
    )
     
    John Crocco, Mar 3, 2004
    #1
  2. John Crocco

    Tom Smith Guest

    Why not get the Express Tools? The TXT2MTXT that comes included works fine
    with a single text object. You don't need a custom lisp.

    The Express Tools come with 2004 and later. Subscription customers got them
    in 2000/2000i and they could be purchased for 2002 for those who didn't
    already have them.
     
    Tom Smith, Mar 3, 2004
    #2
  3. John Crocco

    bellenoit Guest

    Has anyone "fixed" the underline issue with txt2mtxt?

    get rid of them annoying %%u's!

    just wondering...

    noit
     
    bellenoit, Mar 4, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.