Author Topic: txt2mtxt  (Read 17640 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: txt2mtxt
« Reply #15 on: October 28, 2010, 03:18:42 PM »
Robert,
Please post a sample DWG like the one you are working with.

I'm moving this thread to the lisp forum.

Thanks
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

jaydee

  • Guest
Re: txt2mtxt
« Reply #16 on: October 28, 2010, 09:04:45 PM »
Hi.
Just wondering if someone be able to take this further and convert it to individual groups of MTEXT, instead of lumping all selected text into one mtext.
ie.
say i make a mtext with multiple lines, then copy it a few times ramdomly around the screen, then explode all the mtext. And now try  to select all the text and still be able to convert it back to individual mtext (ie. convert it to way it was prior to exploding).

Thankyou

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: txt2mtxt
« Reply #17 on: October 28, 2010, 11:18:32 PM »
That might be difficult if there is no clear rules for determining how to separate each mtext.
Why would you explode mtext? And if there was a good reason then why would you need to put it together again.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

jaydee

  • Guest
Re: txt2mtxt
« Reply #18 on: October 29, 2010, 12:01:27 AM »
Hi CAB.
Its just an example to show how i would like to have a routine to convert text to mtext. (i have seen lisp that either convert all select text to a single mtext or convert every single line text to mtext as separate item).
So often we need to update an old drawings or drawings from others that only used the old Dtext, but those text still stack up as paragraphs such as scattered inplace notes on the drawing. I know i could used xpress tool to convert these, but if the drawing consisted of hundreds of dtext paragaphs, then it would be a very tedious selection.

I think the rules is if the dtext is 2.5mm height, then if the next text line is between 3&5mm below it (same x coordinates), then i would assume its the same paragraph, therefore group these together as Mtext. and move on to convert the next group of text with the same rule.

Thankyou

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: txt2mtxt
« Reply #19 on: October 29, 2010, 08:56:00 AM »
OK I see what you meant to do. You may find this routine interesting.
http://www.theswamp.org/index.php?topic=2133.msg27500#msg27500
It detects overlap but may be converted to detect adjacent mtext.


Later.....
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

jaydee

  • Guest
Re: txt2mtxt
« Reply #20 on: November 01, 2010, 06:39:44 PM »
Thanks CAB
I will look into it, but looks like its to deep for me to make use of it for now.
cheers

jmcshane

  • Newt
  • Posts: 83
Re: txt2mtxt
« Reply #21 on: November 02, 2010, 06:03:15 AM »
Nice work Ron. Much better than my simple solution.
Nice work Gentlemen,
but Alan, your simple code is exactly what I have been looking for.

Many thanks to you both.

John
John.

Civil 3D 2021. Windows 10

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: txt2mtxt
« Reply #22 on: November 02, 2010, 12:17:18 PM »
Nice work Ron. Much better than my simple solution.
Nice work Gentlemen,
but Alan, your simple code is exactly what I have been looking for.

Many thanks to you both.

John
Well then, enjoy.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7527
Re: txt2mtxt
« Reply #23 on: November 02, 2010, 04:53:27 PM »
Hi.
Just wondering if someone be able to take this further and convert it to individual groups of MTEXT, instead of lumping all selected text into one mtext.
ie.
say i make a mtext with multiple lines, then copy it a few times ramdomly around the screen, then explode all the mtext. And now try  to select all the text and still be able to convert it back to individual mtext (ie. convert it to way it was prior to exploding).

Thankyou

Had a bit of free time today. This will sort by common X values (fuzz of text height) and group the text. It does not break up text in the same column if the spacing is greater than 2X the height.

Have fun :)

Code: [Select]
;;; AUTHOR
;;; Copyright© 2010 Ron Perez (ronperez@gmail.com)
;;; 11.02.2010 added grouping text by X values
(defun c:t2mt (/   rjp-removextraspaces rjp-ent2obj       rjp-getbbwdth
       rjp-getbbtlc      rjp-dxf d    doc       elst hgt
       i   n      nxt obj    otxt       out pt
       ss   txt      w x    x_sort     y
      )
  (defun rjp-removextraspaces (txt)
    (while (vl-string-search "  " txt) (setq txt (vl-string-subst " " "  " txt)))
    txt
  )
  (defun rjp-ent2obj (ent)
    (if (= (type ent) 'ename)
      (vlax-ename->vla-object ent)
      ent
    )
  )
  (defun rjp-dxf (code ent)
    (if (and ent (= (type ent) 'ename))
      (cdr (assoc code (entget ent)))
    )
  )
  (defun rjp-getbb (ent / ll ur)
    (vla-getboundingbox (rjp-ent2obj ent) 'll 'ur)
    (mapcar 'vlax-safearray->list (list ll ur))
  )
  (defun rjp-getbbwdth (ent / out)
    (setq out (mapcar 'car (rjp-getbb (rjp-ent2obj ent))))
    (abs (- (car out) (cadr out)))
  )
  (defun rjp-getbbtlc (ent / out)
    (setq out (rjp-getbb (rjp-ent2obj ent)))
    (list (caar out) (cadr (last out)) 0.0)
  )
  (if (and (setq ss (ssget ":L" (list '(0 . "text"))))
   (setq doc (vla-get-activedocument (vlax-get-acad-object)))
   ;;list as X Y TEXT ENAME
   (setq elst (mapcar '(lambda (x)
(list (car (rjp-dxf 10 x))
       (cadr (rjp-dxf 10 x))
       (strcat (rjp-removextraspaces (rjp-dxf 1 x)) " ")
       x
)
       )
      (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      )
   )
      )
    (progn
      ;;Sort top to bottom
      (setq elst (vl-sort elst '(lambda (y1 y2) (> (cadr y1) (cadr y2)))))
      ;;Group by x values using text height as fuzz value
      (while (setq i (car elst))
(setq y (vl-remove-if-not '(lambda (x) (equal (car i) (car x) (rjp-dxf 40 (last i)))) elst))
(mapcar '(lambda (x) (setq elst (vl-remove x elst))) y)
(setq x_sort (cons y x_sort))
      )
      (foreach item x_sort
(setq ;;Get widest piece of text to set mtext width
      w    (* 1.0125 (car (vl-sort (mapcar 'rjp-getbbwdth (mapcar 'last item)) '>)))
      hgt  (rjp-dxf 40 (last (car item)))
      pt   (rjp-getbbtlc (last (car item)))
      ;;Grab top text to pull properties from
      otxt (vlax-ename->vla-object (last (car item)))
)
;;Puts hard returns for text spaced greater than (* 2. hgt)
(setq n 0)
(foreach x item
  (if (setq nxt (nth (setq n (1+ n)) item))
    (if (>= (setq d (abs (- (cadr x) (cadr nxt)))) (* 2. hgt))
      (setq out (cons (strcat (caddr x) "\\P\\P") out))
      (setq out (cons (caddr x) out))
    )
    (setq out (cons (caddr x) out))
  )
)
;;Join the text into one string
(setq txt (apply 'strcat (reverse out)))
;;Insert mtext
(setq obj (vla-addmtext
    (if (= (getvar 'cvport) 1)
      (vla-get-paperspace doc)
      (vla-get-modelspace doc)
    )
    (vlax-3d-point pt)
    w
    txt
  )
      txt nil
      out nil
)
;;Match properties from top text object
(vla-put-height obj (vla-get-height otxt))
(vla-put-attachmentpoint obj actopleft)
(vlax-put obj 'insertionpoint pt)
(vla-put-rotation obj 0.0)
(vla-put-layer obj (vla-get-layer otxt))
(vla-put-stylename obj (vla-get-stylename otxt))
;;Delete selected single line text
(mapcar 'entdel (mapcar 'last item))
      )
    )
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: txt2mtxt
« Reply #24 on: November 02, 2010, 05:13:57 PM »
Very nice Ron. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: txt2mtxt
« Reply #25 on: November 02, 2010, 05:22:07 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: txt2mtxt
« Reply #26 on: November 02, 2010, 05:24:10 PM »
Daaaaamn, nice work Ron.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7527
Re: txt2mtxt
« Reply #27 on: November 02, 2010, 05:34:35 PM »
Daaaaamn, nice work Ron.

Thanks Alan  :-D Hopefully some people can get some use out of it.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jaydee

  • Guest
Re: txt2mtxt
« Reply #28 on: November 02, 2010, 08:10:01 PM »
Very nice RONJONP.
"It does not break up text in the same column if the spacing is greater than 2X the height."

Is this something that you might be able to looking into in the future. Really appreciated if this last puzzle could be solve to covert paragraphs in the same column into separate mtext paragraph.

Thankyou verymuch.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: txt2mtxt
« Reply #29 on: November 04, 2010, 12:45:33 PM »
Very nice RONJONP.
"It does not break up text in the same column if the spacing is greater than 2X the height."

Is this something that you might be able to looking into in the future. Really appreciated if this last puzzle could be solve to covert paragraphs in the same column into separate mtext paragraph.

Thankyou verymuch.

I'll try and get to it next week.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC