PDA

View Full Version : Combine separate MTEXT paragraphs



beardking
2010-05-20, 02:34 PM
I am trying to convert the people in my office to using MTEXT and I'm somewhat successful at it. One of the problems I'm having is people keep making a bunch of separate paragraphs with MTEXT rather than having all of the paragraphs in one MTEXT entity. Is there any way to quickly convert a bunch of different MTEXT entities into 1 single entity?

I have attached an example to clarify what I mean.

Thanks in advance

Glenn Pope
2010-05-20, 03:49 PM
For each paragraph I set the mtext to 0 width so I get one lone line. Then exploded it. Then use TXT2MTXT and select all the single line texts (make sure uncheck "Create word-wrap MText" in the settings).

CadDog
2010-05-20, 06:04 PM
I am trying to convert the people in my office to using MTEXT and I'm somewhat successful at it. One of the problems I'm having is people keep making a bunch of separate paragraphs with MTEXT rather than having all of the paragraphs in one MTEXT entity. Is there any way to quickly convert a bunch of different MTEXT entities into 1 single entity?

I have attached an example to clarify what I mean.

Thanks in advance

Mtext is cool and getting cooler...

I have a few tools that can help you help your users. Here are two...

>>> Text Join (which join dtext to dtext and/or mtext to mtext
>>> Plus I also use _txt2mtxt to convert dtext to mtext...

Here is TextJoin which I call "TJ" as a quick keyin:




;TextJoin... :)
(defun C:TJ (/ intCount entSelection objSelection
objSelection1 ssSelections btwtxt)
; (vl-load-com) ;no longer needed in Autocad 2005
(princ "\nSelect First Text or MText Entity: ")
(while (not (and (setq ssSelections (ssget ":S" (list (cons 0 "TEXT,MTEXT"))))
(setq entSelection (ssname ssSelections 0))
(setq objSelection1 (vlax-ename->vla-object entSelection))
)
)
(princ "\nError with selection please select again: ")
)
(if(=(cdr(assoc 0 (entget entSelection))) "MTEXT")
(setq btwtxt "\\P") ;Return in MText.
(setq btwtxt " ") ;Or space between Text selections.
)
(redraw(ssname(ssget "P")0)3) ;Highlight First selection.
(princ "\nSelect text or mtext entities to add to first: ")
(setq thisdrawing (vla-get-activedocument (vlax-get-acad-object))
ssSelections (ssget (list (cons 0 "TEXT,MTEXT")))
intCount 0 ;Start with first selection.
)
(if(ssmemb entSelection ssSelections)(ssdel entSelection ssSelections))
; Don't delete First selection if selected again.
(repeat (sslength ssSelections)
(vla-startundomark thisdrawing)
(setq entSelection (ssname ssSelections intCOunt)
objSelection (vlax-ename->vla-object entSelection)
intCount (1+ intCount) ;increment to next selection.
)
(if(= btwtxt " ")
(while(vl-string-search "\\P" (vla-get-textstring objSelection))
(vla-put-textstring objSelection
(vl-string-subst " " "\\P" (vla-get-textstring objSelection))
)
)
)
(vla-put-textstring objSelection1
(strcat
(vla-get-textstring objSelection1)
btwtxt
(vla-get-textstring objSelection)
)
)
(vla-delete objSelection)
(vla-endundomark thisdrawing)
)
(princ)
)Moderator Note:



Enjoy...!!!
:)

scott.wilcox
2010-05-20, 06:32 PM
Thanks, that's awesome!

beardking
2010-05-20, 10:52 PM
Mtext is cool and getting cooler...

I have a few tools that can help you help your users. Here are two...

>>> Text Join (which join dtext to dtext and/or mtext to mtext
>>> Plus I also use _txt2mtxt to convert dtext to mtext...

Sweet, that is awesome. That's going in my personal directory for sure. :)

CadDog
2010-05-24, 05:41 PM
Sweet, that is awesome. That's going in my personal directory for sure. :)


That's great but don't forget to share with others...

They may come up with an better idea...

More heads are better then one...

*****
I notice your "

"Using AutoCAD 2009 to about 60% of it's potential daily. "

I hope you know about annotation text and there problems and how to fix them...

This start in 2007, 2008 and still in 2009...

:)

Has been fixed in 2010...

irneb
2010-05-25, 07:27 AM
Just one prob I can see with your code. You use the vla-get-TextString ... be carefull with this as it screws up special characters. Here's a "quicky" of my own, joins both MText & DText together into the 1st selected MText. Keeps any annoscaling in tact (other than when using entmod), and works with special characters other than using vla-get-TextString.
;;; Join 2 or more texts together
(defun c:TextJoin (/ ss n en ed eo txt)
(princ "Select text entities in order: ")
(if (and (setq ss (ssget '((0 . "MTEXT,TEXT")))) ;Select both MText & DText
(> (sslength ss) 1) ;Check if more than one selected
) ;_ end of and
(progn
(setq n 1 ;Initialize counter
en (ssname ss 0) ;Get 1st selected
ed (entget en) ;Get its DXF data
txt (cdr (assoc 1 ed)) ;Get its textvalue
) ;_ end of setq
(if (= (cdr (assoc 0 ed)) "TEXT") ;If the 1st is a DText
(progn
(command "txt2mtxt" en "") ;Convert it to a MText
(setq en (entlast)) ;Get the new MText
) ;_ end of progn
) ;_ end of if
(setq eo (vlax-ename->vla-object en)) ;Get the ActiveX object of the 1st text
(while (< n (sslength ss)) ;Step through the rest of the selected text
(setq en (ssname ss n) ;Get the nth text
ed (entget en) ;Get its DXF data
) ;_ end of setq
(setq txt (strcat txt "\\P" (cdr (assoc 1 ed)))) ;Append its string to add to the 1st text
(entdel en) ;Delete the nth text
(setq n (1+ n)) ;Increment the counter
) ;_ end of while
(vla-put-TextString eo txt) ;Modify the 1st text to the concatenated string
) ;_ end of progn
) ;_ end of if
(princ)
) ;_ end of defun

batts2001368787
2013-04-03, 07:42 PM
Just one prob I can see with your code. You use the vla-get-TextString ... be carefull with this as it screws up special characters. Here's a "quicky" of my own, joins both MText & DText together into the 1st selected MText. Keeps any annoscaling in tact (other than when using entmod), and works with special characters other than using vla-get-TextString.
;;; Join 2 or more texts together
(defun c:TextJoin (/ ss n en ed eo txt)
(princ "Select text entities in order: ")
(if (and (setq ss (ssget '((0 . "MTEXT,TEXT")))) ;Select both MText & DText
(> (sslength ss) 1) ;Check if more than one selected
) ;_ end of and
(progn
(setq n 1 ;Initialize counter
en (ssname ss 0) ;Get 1st selected
ed (entget en) ;Get its DXF data
txt (cdr (assoc 1 ed)) ;Get its textvalue
) ;_ end of setq
(if (= (cdr (assoc 0 ed)) "TEXT") ;If the 1st is a DText
(progn
(command "txt2mtxt" en "") ;Convert it to a MText
(setq en (entlast)) ;Get the new MText
) ;_ end of progn
) ;_ end of if
(setq eo (vlax-ename->vla-object en)) ;Get the ActiveX object of the 1st text
(while (< n (sslength ss)) ;Step through the rest of the selected text
(setq en (ssname ss n) ;Get the nth text
ed (entget en) ;Get its DXF data
) ;_ end of setq
(setq txt (strcat txt "\\P" (cdr (assoc 1 ed)))) ;Append its string to add to the 1st text
(entdel en) ;Delete the nth text
(setq n (1+ n)) ;Increment the counter
) ;_ end of while
(vla-put-TextString eo txt) ;Modify the 1st text to the concatenated string
) ;_ end of progn
) ;_ end of if
(princ)
) ;_ end of defun





Here's one that will do it all in one step :mrgreen:

; ----------------------------------------------------------------------
; (Converts Stack of TEXT to MTEXT)
; Copyright (C) 1998 DotSoft, All Rights Reserved
; Website: www.dotsoft.com
; ----------------------------------------------------------------------
; DISCLAIMER: DotSoft Disclaims any and all liability for any damages
; arising out of the use or operation, or inability to use the software.
; FURTHERMORE, User agrees to hold DotSoft harmless from such claims.
; DotSoft makes no warranty, either expressed or implied, as to the
; fitness of this product for a particular purpose. All materials are
; to be considered ‘as-is’, and use of this software should be
; considered as AT YOUR OWN RISK.
; ----------------------------------------------------------------------
;edited by Fred Zweig 09-06-12


(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:TT2 ( / 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)
)





Enjoy! - Jay

CJP123321360699
2013-10-10, 02:13 PM
Thanks a bunch for this!