Author Topic: Auto-combine "text clusters" into MText paragraphs  (Read 2046 times)

0 Members and 1 Guest are viewing this topic.

cadpoobah

  • Newt
  • Posts: 49
Auto-combine "text clusters" into MText paragraphs
« on: December 19, 2017, 11:02:28 AM »
All,

I have a drawing that contains many individual pieces of MText that look like they should belong to "paragraphs", but each line is a separate piece of MText. I need to combine them each pseudo-paragraph into a true piece of MText.

I realize that this can be done with manually TXT2MTXT, but this needs done to a number of drawings, so I'd rather not need user interaction. I'd like it to do the following:
- evaluate each piece of text to determine if it's part of a paragraph (i.e. whether there is text above or below it, based on known line spacing)
- determine which piece is the 1st line of the paragraph (i.e. using the known spacing, there's no more text above it)
- combine it with the text below it (the rest of the paragraph, again using the known spacing)

BTW, the line spacing is <txt ht> * 1.61111.

It seems like a recursive exercise, but I don't do recursive very well.

Any takers?

Thanks,

Chris
Chris Lindner
Onebutton CAD Solutions
----------------------------------------------------
www.onebuttoncad.com #dayjob
www.unpavedart.com    #sidehustle

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Auto-combine "text clusters" into MText paragraphs
« Reply #1 on: December 19, 2017, 11:07:24 AM »
Perhaps something like THIS.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cadpoobah

  • Newt
  • Posts: 49
Re: Auto-combine "text clusters" into MText paragraphs
« Reply #2 on: December 19, 2017, 12:43:56 PM »
Perhaps something like THIS.

Dang! That's beautiful.

I tweaked the following:
- changed (ssget ":L" (list '(0 . "text"))) to (ssget ":L" (list '(0 . "*text"))) to catch my MText.
- changed fuz-y to 2.5 from 4

The new MText is wider than I want (see below; red is new), but it's the fault of the existing MText objects; their box widths are wider than necessary (as indicated by the grips). I may opt to "explode" the MText to just Text before combining it. That seemed to work much more predictably.

I realize now that I created my own mess by changing your ssget statement.  :whistling:

Idea: it would be nice to "optimize" the MText box (to be only as wide as necessary) before processing the MText entities, thus making it convert similar to Text.

Thanks, Ron! You are vastly underpaid, my friend!
« Last Edit: December 19, 2017, 12:51:38 PM by cadpoobah »
Chris Lindner
Onebutton CAD Solutions
----------------------------------------------------
www.onebuttoncad.com #dayjob
www.unpavedart.com    #sidehustle

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Auto-combine "text clusters" into MText paragraphs
« Reply #3 on: December 19, 2017, 02:55:17 PM »
Try changing the definition for rjp-getbbwdth to:
Code: [Select]
(defun rjp-getbbwdth ( ent / enx )
    (if (= "TEXT" (cdr (assoc 0 (setq enx (entget ent)))))
        ((lambda ( box ) (- (caadr box) (caar box))) (textbox enx))
        (cdr (assoc 42 enx))
    )
)

cadpoobah

  • Newt
  • Posts: 49
Re: Auto-combine "text clusters" into MText paragraphs
« Reply #4 on: December 19, 2017, 06:38:50 PM »
Try changing the definition for rjp-getbbwdth to:
Code: [Select]
(defun rjp-getbbwdth ( ent / enx )
    (if (= "TEXT" (cdr (assoc 0 (setq enx (entget ent)))))
        ((lambda ( box ) (- (caadr box) (caar box))) (textbox enx))
        (cdr (assoc 42 enx))
    )
)

Thanks, Lee.

I see that this is looking for the bounding box of TEXT. TEXT  was working fine, but MTEXT was problematic. That's why I ended up exploding the MTEXT first; the TEXT boxes were more predictable.

Maybe I misunderstood what your mod was supposed to accomplish.
Chris Lindner
Onebutton CAD Solutions
----------------------------------------------------
www.onebuttoncad.com #dayjob
www.unpavedart.com    #sidehustle

cadpoobah

  • Newt
  • Posts: 49
Re: Auto-combine "text clusters" into MText paragraphs
« Reply #5 on: December 19, 2017, 06:43:46 PM »
Perhaps something like THIS.

Ron,

Another tweak that I would find helpful would be if it would only combine text objects that had the same TextStyle. I realize this is a possible "rabbit hole", as others may want to only combine text with matching heights, layers, etc.

In your routine, how/where would I add the TextStyle condition?

Thanks again!
Chris Lindner
Onebutton CAD Solutions
----------------------------------------------------
www.onebuttoncad.com #dayjob
www.unpavedart.com    #sidehustle

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Auto-combine "text clusters" into MText paragraphs
« Reply #6 on: December 19, 2017, 06:54:14 PM »
Try changing the definition for rjp-getbbwdth to:
Code: [Select]
(defun rjp-getbbwdth ( ent / enx )
    (if (= "TEXT" (cdr (assoc 0 (setq enx (entget ent)))))
        ((lambda ( box ) (- (caadr box) (caar box))) (textbox enx))
        (cdr (assoc 42 enx))
    )
)

Thanks, Lee.

I see that this is looking for the bounding box of TEXT. TEXT  was working fine, but MTEXT was problematic. That's why I ended up exploding the MTEXT first; the TEXT boxes were more predictable.

Maybe I misunderstood what your mod was supposed to accomplish.

Did you try it?

The function will calculate the width of the text content of both TEXT and MTEXT, rather than using the MTEXT frame.

cadpoobah

  • Newt
  • Posts: 49
Re: Auto-combine "text clusters" into MText paragraphs
« Reply #7 on: December 19, 2017, 09:06:54 PM »
Did you try it?

The function will calculate the width of the text content of both TEXT and MTEXT, rather than using the MTEXT frame.

Yes, buy I didn't notice any difference. I'll give it another go in the morning.
Chris Lindner
Onebutton CAD Solutions
----------------------------------------------------
www.onebuttoncad.com #dayjob
www.unpavedart.com    #sidehustle

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Auto-combine "text clusters" into MText paragraphs
« Reply #8 on: December 20, 2017, 12:45:58 PM »
Perhaps something like THIS.

Dang! That's beautiful.

I tweaked the following:
- changed (ssget ":L" (list '(0 . "text"))) to (ssget ":L" (list '(0 . "*text"))) to catch my MText.
- changed fuz-y to 2.5 from 4

The new MText is wider than I want (see below; red is new), but it's the fault of the existing MText objects; their box widths are wider than necessary (as indicated by the grips). I may opt to "explode" the MText to just Text before combining it. That seemed to work much more predictably.

I realize now that I created my own mess by changing your ssget statement.  :whistling:

Idea: it would be nice to "optimize" the MText box (to be only as wide as necessary) before processing the MText entities, thus making it convert similar to Text.

Thanks, Ron! You are vastly underpaid, my friend!
Glad to help out :) .. I'd tidy up the code a bit, but I'm busy with real work right now.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC