Author Topic: Middle Center justify text in rectangle?  (Read 12130 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Middle Center justify text in rectangle?
« Reply #30 on: December 15, 2009, 01:05:09 PM »
Don't quite understand what you are asking.
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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Middle Center justify text in rectangle?
« Reply #31 on: December 15, 2009, 01:11:47 PM »
So that the MTEXT window is at each corner of the cell ... not easy  :|

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Middle Center justify text in rectangle?
« Reply #32 on: December 15, 2009, 02:55:48 PM »
What condition would this help?

Set width to zero.
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.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Middle Center justify text in rectangle?
« Reply #33 on: December 15, 2009, 04:18:17 PM »
What condition would this help?

Set width to zero.


I was thinking if the width was too narrow or too wide, text might pop out top and bottom or left and right of cell.  If it was 0 width, line breaks may not be present.

Might be overthinking...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Middle Center justify text in rectangle?
« Reply #34 on: December 15, 2009, 05:51:40 PM »
With Plain Text you can adjust the with factor if there is over flow.
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Middle Center justify text in rectangle?
« Reply #35 on: December 16, 2009, 12:50:40 AM »
Updating my version to include Mtext.
Code: [Select]
;;  Example by CAB
;;  Moves Text or Mtext to center while justifying Middle Center
;;  Changes Mtest to Width Zero
(defun c:CenterText (/ ss i elast obj bent ipt prop)
  (defun getmid (ent)
    (setq lst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget ent))))
    (if (= (length lst) 4)
      (mapcar '(lambda (a b) (/ (+ a b) 2.)) (car lst) (caddr lst))
    )
  )

  (command "_undo" "begin")
  (prompt "\Select text within the table.")
  (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
    (progn
      (setq i -1)
      (while (setq ename (ssname ss (setq i (1+ i))))
        (setq obj (vlax-ename->vla-object ename))
        (if (eq "AcDbText" (vla-get-ObjectName obj))
          (setq prop 'TextAlignmentPoint)
          (setq prop 'insertionpoint)
        )
        (setq elast (entlast))
        (setq ipt (vlax-get obj 'insertionpoint))
        (if (vl-catch-all-error-p
              (vl-catch-all-apply
                '(lambda ()
                   (vl-cmdf "_.-boundary" "_a" "_i" "_n" "" "" ipt "")
                   (while (> (getvar "CMDACTIVE") 0) (command ""))
                 )))
          (princ "\nText boundry not found.")
          (progn ;  got a boundry
            (if (and (not (eq elast (setq bent (entlast))))
                     (setq midpt (getmid bent))
                )
              (if (eq "AcDbText" (vla-get-ObjectName obj))
                (progn
                  (vla-put-Alignment obj acAlignmentMiddleCenter)
                  (vla-put-TextAlignmentPoint Obj (vlax-3D-point MidPT))
                )
                (progn
                  (vla-put-Width obj 0.0)
                  (vla-put-AttachmentPoint obj acAttachmentPointMiddleCenter)
                  (vla-put-insertionpoint Obj (vlax-3D-point MidPT))
                )
              )
            )
            (and (eq bent (entlast)) (entdel bent))
          )
        )
      )
    )
  )
  (command "_undo" "end")

  (princ)
)
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.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Middle Center justify text in rectangle?
« Reply #36 on: December 16, 2009, 11:17:10 AM »
Updating my version to include Mtext.

NICE CAB!