Author Topic: Dynamic Text Alignment  (Read 27253 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Dynamic Text Alignment
« on: October 10, 2009, 10:09:58 AM »
Had a bit of time free last night, was toying around with this idea - will let the user align text horizontally/vertically at any angle.

Not sure if its been done before or not...





Code: [Select]
;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;;
;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,¤º°`°º¤;;;
;;                                                                               ;;
;;                      --=={  Dynamic Text Align  }==--                         ;;
;;                                                                               ;;
;;  Allows the user to dynamically align text to any angle. User is prompted to  ;;
;;  make a selection of Text or MText objects to align, and pick an alignment    ;;
;;  point, or select a text object to use for alignment. The selection of text   ;;
;;  is then aligned by either x or y coordinate, or dynamically stretched        ;;
;;  depending on the mode chosen.                                                ;;
;;                                                                               ;;
;;  The mode can be switched upon pressing TAB during alignment. Text and MText  ;;
;;  entities will be aligned in accordance with their respective justifications. ;;
;;                                                                               ;;
;;  The user can also specify a fixed text spacing, by pressing 'S' during text  ;;
;;  alignment. Holding Shift whilst aligning Text will alter Text Rotation, the  ;;
;;  user can also refine Rotation by pressing 'R' during text alignment. Text    ;;
;;  Justfication can be altered by pressing 'J' during text alignment.           ;;
;;                                                                               ;;
;;                                                                               ;;
;;  Object Alignment Mode:-                                                      ;;
;;  --------------------------                                                   ;;
;;  Text can be aligned to an object by pressing 'O' during text alignment. In   ;;
;;  this mode, the text spacing along the object can be adjusted by pressing     ;;
;;  'S' and the text offset from the object can also be altered by pressing 'O'. ;;
;;                                                                               ;;
;;  Text Rotation can be aligned to the tangent vector of the object at the      ;;
;;  point of alignment by holding Shift during text placement. The user can      ;;
;;  furthermore specify a text rotation by pressing 'R'.                         ;;
;;                                                                               ;;
;;  The order of the text entities along the object can be Reversed by pressing  ;;
;;  'V' during Text placement. The original order of these entities is           ;;
;;  determined by the drawing direction of the object.                           ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  FUNCTION SYNTAX:  TXALIGN                                                    ;;
;;                                                                               ;;
;;  Notes:-                                                                      ;;
;;  ---------                                                                    ;;
;;  Shift Functionality requires the user to have Express Tools installed.       ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  AUTHOR:                                                                      ;;
;;                                                                               ;;
;;  Copyright © Lee McDonnell, October 2009. All Rights Reserved.                ;;
;;                                                                               ;;
;;      { Contact: Lee Mac @ TheSwamp.org, CADTutor.net }                        ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  VERSION:                                                                     ;;
;;                                                                               ;;
;;    ø 1.0   ~¤~   12th October 2009   ~¤~   º First Release                    ;;
;;...............................................................................;;
;;    ø 1.1   ~¤~   14th October 2009   ~¤~   º Added ability to Specify fixed   ;;
;;                                              text spacing                     ;;
;;...............................................................................;;
;;    ø 1.2   ~¤~   15th October 2009   ~¤~   º Added Stretch Mode               ;;
;;                                            º Upgraded User messaging          ;;
;;...............................................................................;;
;;    ø 1.3   ~¤~   18th October 2009   ~¤~   º Added Rotation Functionality     ;;
;;...............................................................................;;
;;    ø 1.4   ~¤~   20th October 2009   ~¤~   º Added functionality to align     ;;
;;                                              text to object.                  ;;
;;...............................................................................;;
;;    ø 1.5   ~¤~   23rd October 2009   ~¤~   º Added Justification Options.     ;;
;;...............................................................................;;
;;    ø 1.6   ~¤~   28th October 2009   ~¤~   º Added Option to Select Text      ;;
;;                                              object at Alignment Point prompt ;;
;;...............................................................................;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;;
;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,¤º°`°º¤;;;

[ Code updated to Version 1.6 ]

Read the code header for help  :-)

Code available here.
« Last Edit: November 14, 2010, 08:07:56 PM by Lee Mac »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dynamic Text Alignment
« Reply #1 on: October 10, 2009, 11:05:58 AM »
Looks like a dynamic bonanza around here. :roll:

Very cool.
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.

SteveK

  • Guest
Re: Dynamic Text Alignment
« Reply #2 on: October 11, 2009, 05:13:31 PM »
I think I'm gonna find that extremely useful! Thanks Lee (Though I thought you are meant to be studying now...)

SteveK

  • Guest
Re: Dynamic Text Alignment
« Reply #3 on: October 11, 2009, 05:15:29 PM »
So yeah, looking forward to it. Though hopefully you can integrate a feature that allows for static vertical or horizontal (ie it'll just align one)

Hugo

  • Bull Frog
  • Posts: 422
Re: Dynamic Text Alignment
« Reply #4 on: October 12, 2009, 02:45:54 AM »
Hallo Lee

Sieht Tool aus, aber wo kann man das Uploden

Bakerman

  • Guest
Re: Dynamic Text Alignment
« Reply #5 on: October 12, 2009, 07:00:05 AM »

Hey, I think I could use something like that. Nice job!  :-)


Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Text Alignment
« Reply #6 on: October 12, 2009, 08:00:56 AM »
Thanks guys,

Haven't had too much time as you know, but will get the code on here asap  ;-)


Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Text Alignment
« Reply #7 on: October 12, 2009, 08:01:50 AM »
So yeah, looking forward to it. Though hopefully you can integrate a feature that allows for static vertical or horizontal (ie it'll just align one)

With regards to the static vertical/horizontal alignment, you can hit Ortho for these  :wink:

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Dynamic Text Alignment
« Reply #8 on: October 12, 2009, 08:45:52 AM »
Very cool beans.  I will give it a try. 

Maybe along the alignment feature throw in a "Enter amount of clear space between" user input variable/feature.  Pretty please with sugar on top.  :roll: :-)

Which is on my to-do list to add to antiquated text alignment proggy that I have. 
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dynamic Text Alignment
« Reply #9 on: October 12, 2009, 11:27:10 AM »
Very cool beans.  I will give it a try. 

Maybe along the alignment feature throw in a "Enter amount of clear space between" user input variable/feature.  Pretty please with sugar on top.  :roll: :-)

Which is on my to-do list to add to antiquated text alignment proggy that I have. 


Here is one I wrote awhile ago, not dynamic or anything though.......  :-)

Code: [Select]
(defun c:SpaceNotes (/ TxtRot TxtList TxtHt Obj NewInsPt InsPt Ent Dis1 StyObj DftHt TxtSty StyList curSty
    temp1 temp2 ss ocmd SpaceRatio)
;|
    Used to line up notes equally spaced vertically.
    By Tim Willey   Dec. 2004
    Sub's 'tmw:ss->Objlist 'tmw:Var->Safe 'MakeX 'value
    |;
   
    (setq ocmd (getvar "cmdecho")) (setvar "cmdecho" 0)
    (setq ActDoc (vla-get-ActiveDocument (vlax-get-ACAD-Object)))
    (vlax-invoke-method ActDoc 'StartUndoMark)
    (setvar "errno" 0)
    (while
        (and
            (not Ent)
            (/= (getvar "errno") 52)
        )
        (setq Ent (entsel "\n Select first note object: "))
        (if
            (and
                Ent
                (or
                    (= (value 0 (entget (car Ent))) "TEXT")
                    (= (value 0 (entget (car Ent))) "ATTDEF")
                )
                (not (redraw (car Ent) 3))
                (if (not (setq SpaceRatio (getdist "\n Enter ratio of typical distance between text objects [1.0]: ")))
                    (setq SpaceRatio 1.0)
                    T
                )
            )
            (progn
                (setq Obj (MakeX (car Ent)))
                (if (= (vla-get-Alignment Obj) 0)
                    (setq InsPt (safearray-value (variant-value (vla-get-InsertionPoint Obj))))
                    (setq InsPt (safearray-value (variant-value (vla-get-TextAlignmentPoint Obj))))
                )
                (setq TxtHt (vla-get-Height Obj))
                (setq TxtRot (vla-get-Rotation Obj))
                (setq TxtSty (vla-get-StyleName Obj))
                (setq CurSty (vla-get-ActiveTextStyle ActDoc))
                (setq StyList (vla-get-TextStyles ActDoc))
                (vlax-for item StyList
                    (if (= (vla-get-Name item) TxtSty)
                        (progn
                            (setq StyObj item)
                            (setq DftHt (vla-get-Height item))
                            (vla-put-Height item 0.0)
                        )
                    )
                )
                (vla-put-ActiveTextStyle ActDoc StyObj)
                (command "_.text" InsPt TxtHt TxtRot "N")
                (setq temp1 (entlast))
                (command "_.text" "" "N")
                (setq temp2 (entlast))
                (setq Dis1 (* SpaceRatio (distance (value 10 (entget temp1)) (value 10 (entget temp2)))))
                (vla-Delete (MakeX temp1))
                (vla-Delete (MakeX temp2))
                (if (setq ss (ssget '((0 . "TEXT,ATTDEF"))))
                    (progn
                        (setq TxtList (tmw:ss->Objlist ss))
                        (setq TxtList
                            (vl-sort
                                TxtList
                                '(lambda (a b)
                                    (>
                                        (cadr (tmw:Var->Safe (vla-get-InsertionPoint a)))
                                        (cadr (tmw:Var->Safe (vla-get-InsertionPoint b)))
                                    )
                                )
                            )
                        )
                        (foreach item TxtList
                            (setq InsPt (list (car InsPt) (- (cadr InsPt) Dis1) (caddr InsPt)))
                            (setq NewInsPt (vlax-3d-point InsPt))
                            (if (= (vla-get-Alignment item) 0)
                                (vla-put-InsertionPoint item NewInsPt)
                                (vla-put-TextAlignmentPoint item NewInsPt)
                            )
                        )
                    )
                )
            )
        )
    )
    (setvar "cmdecho" ocmd)
    (if Ent
        (progn
            (redraw (car Ent) 4)
            (vla-put-Height StyObj DftHt)
            (vla-put-ActiveTextStyle ActDoc CurSty)
        )
    )
    (vlax-invoke-method ActDoc 'EndUndoMark)
    (princ)
)
(defun MakeX (entname)
(vlax-ename->vla-object entname)
)
(defun tmw:ss->Objlist (ss / RtnList temp1)

(while (setq temp1 (ssname ss 0))
(setq RtnList (cons (vlax-ename->vla-object temp1) RtnList))
(ssdel temp1 ss)
)
RtnList
)
(defun tmw:Var->Safe (VariantValue /)

(if (= (type VariantValue) 'variant)
(safearray-value (variant-value VariantValue))
)
)
(defun VALUE (num ent /)
(cdr (assoc num ent))
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Dynamic Text Alignment
« Reply #10 on: October 12, 2009, 01:59:18 PM »
Very cool beans.  I will give it a try. 
Maybe along the alignment feature throw in a "Enter amount of clear space between" user input variable/feature.  Pretty please with sugar on top.  :roll: :-)

Which is on my to-do list to add to antiquated text alignment proggy that I have. 

Here is one I wrote awhile ago, not dynamic or anything though.......  :-)
And I will give that one a try too.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Text Alignment
« Reply #11 on: October 13, 2009, 07:21:09 AM »
Still haven't got internet at home yet, but got some time to upload the code I have so far  ;-) - see the first post  :-)

Bug reports/Criticism/Comments are of course welcome.

Enjoy,

Lee

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Dynamic Text Alignment
« Reply #12 on: October 13, 2009, 02:17:40 PM »
Nice one Lee...!!

your Idea concept is cool !   :ugly:
Keep Lispin !
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Dynamic Text Alignment
« Reply #13 on: October 13, 2009, 02:47:14 PM »
maybe you can add something like...a rotation ?

Code: [Select]
[color=grey]
.......
  (setq bPt (vlax-get obj prop))
                       (if (setq iPt (inters pt data (polar bPt *tx 1) bPt nil))
                         (vlax-put Obj prop iPt))[/color]
[color=blue]
        (if (and (findfile "AcetUtil.arx") not acet-sys-shift-down)
          (arxload (findfile "AcetUtil.arx"))
        )
        (if (acet-sys-shift-down)
          (vla-put-rotation obj (+ (angle pt data) 1.5708))
        )
[/color]
[color=grey] ) t)
                  (  (= 2 code)                   
                     (cond  (  (= 13 data) nil)
                            (  (= 32 data) nil)[/color]
.....
Keep smile...

Hugo

  • Bull Frog
  • Posts: 422
Re: Dynamic Text Alignment
« Reply #14 on: October 13, 2009, 03:12:03 PM »
Hallo Lee

ein fester Winkel mit 90 oder 0 Grad wäre auch toll.

Danke