Author Topic: Looking for align text routine  (Read 7150 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
Looking for align text routine
« on: March 28, 2006, 10:08:53 AM »
Hi all..

I had somewhere a simple routine to align text and mtext..
but can't find anymore..

is there a way in AutoCAD to do this !?


<Title changed>
« Last Edit: March 28, 2006, 10:23:56 AM by CAB »
Keep smile...

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: align
« Reply #1 on: March 28, 2006, 10:14:59 AM »
By align, do you mean re-stack w/ correct spacing b/t lines?  I have a way to do it w/ VBA for dtext.  OR do you mean make all left justified and line up in a line vertically/horz ?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

whdjr

  • Guest
Re: Looking for align text routine
« Reply #2 on: March 28, 2006, 10:28:13 AM »
There was a routine we used back in R2000 called Talign, I think it was part of the ExpressTools though.  I'll see what I can find.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
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.

paulmcz

  • Bull Frog
  • Posts: 202
Re: Looking for align text routine
« Reply #4 on: March 28, 2006, 11:02:28 AM »
I use this for text and everything:
Code: [Select]
(defun c:rtt (/ ss oan nan p1 rot osn)
  (princ "\n Rotate, Select objects: ")
  (setq ss (ssget))
  (setq oan (getangle "\n Angle to be corrected: "))
  (setq nan (getangle "\n New absolute angle: "))
  (setq p1 (getpoint "\n Base point of rotation: "))
  (setq rot (/ (* (- nan oan) 180) pi))
  (setq osn (getvar "osmode"))
  (setvar "osmode" 0)
  (command "rotate" ss "" p1 rot)
  (setvar "osmode" osn)
  (princ)
  )

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Looking for align text routine
« Reply #5 on: March 28, 2006, 11:11:38 AM »
Here is one I use.
Code: [Select]
(defun c:lu(/ al1 tset0 tset1 al2 al3 alx aly alpt tset2 tlng1 tset3 tset4 al4 al5 al6 tlng2)
; Lines up text

(command "undo" "group")

(setvar "errno" 0)
(setq al1 nil)
(while (and (/= 52 (getvar "errno")) (not al1))
  (initget "X Y")
  (setq al1 (nentsel "\nSelect master text to align along X axis or <\"Y\"> to align along Y axis:  "))
)
(if (or (= al1 "y") (= al1 "Y"))
  (progn
    (setq al1 nil)
    (while (and (/= 52 (getvar "errno")) (not al1))
      (setq al1 (nentsel "\nSelect master text to align along Y axis:  "))
    )
    (setq tset0 al1)
    (setq al1 "y")
  )
  (progn
    (setq tset0 al1)
    (setq al1 "x")
  )
)

(if (= tset0 nil)
  (vl-exit-with-value nil)
  (progn
    (setq tset1 (entget (car tset0)))
    (redraw (cdr (assoc -1 tset1)) 3)
    (setq al2 (cdr (assoc 72 tset1)))
    (setq al3 (cdr (assoc 73 tset1)))
    (if (and (= al2 0) (= al3 0))
      (setq alpt (trans (value 10 tset1) 0 1))
      (setq alpt (trans (value 11 tset1) 0 1))
    )
  )
)
(setq alx (car alpt))
(setq aly (cadr alpt))

(setq tset2 (ssget '((0 . "TEXT"))))
(if (= tset2 nil)
  (progn
    (setq tlng1 0)
    (redraw (cdr (assoc -1 tset1)) 4)
  )
  (setq tlng1 (sslength tset2))
)
(setq tlng2 0)

(repeat tlng1
  (progn
    (setq tset3 (ssname tset2 tlng2))
    (setq tset4 (entget tset3))
    (setq al4 (cdr (assoc 72 tset4)))
    (setq al5 (cdr (assoc 73 tset4)))
    (if (and (= al4 0) (= al5 0))
      (progn
        (setq al6 (trans (value 10 tset4) 0 1))
        (cond
          ((= al1 "x")
          (setq al6 (subst alx (car al6) al6))
          )
          ((= al1 "y")
          (setq al6 (subst aly (cadr al6) al6))
          )
        )
        (setq tset4 (subst (cons 10 (trans al6 1 0)) (assoc 10 tset4) tset4))
        (redraw (cdr (assoc -1 tset1)) 4)
      )
      (progn
        (setq al6 (trans (value 11 tset4) 0 1))
        (cond
          ((= al1 "x")
          (setq al6 (subst alx (car al6) al6))
          )
          ((= al1 "y")
          (setq al6 (subst aly (cadr al6) al6))
          )
        )
        (setq tset4 (subst (cons 11 (trans al6 1 0)) (assoc 11 tset4) tset4))
        (redraw (cdr (assoc -1 tset1)) 4)
      )
    )
    (entmod tset4)
    (setq tlng2 (1+ tlng2))
  )
)

(command "undo" "end")
(princ)

)
Tim

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

Please think about donating if this post helped you.

RbtDanforth

  • Guest
Re: Looking for align text routine
« Reply #6 on: March 28, 2006, 07:43:06 PM »
I ended up writing quite a number of align commands depending on the situation.

You can jus plain move the parts using (command "move"etc
or you can change the Assoc 10 or 11 values
and there is also the case when the text in question is attributes
and the case when we are talking dimensions Mostly just using the #13 & 14 points

I added the Trans function so if I wanted something other than orthogonal I just moved the ucs to the new angle.
Code: [Select]
;PROG TO ALIGN X VALUES OF SELECTION SET
(DEFUN C:AX (/ A B C D E F G)
            (PRINC "CRITS TO ALIGN...")
       (SETQ A (SSGET)
             B (CAR (GETPOINT "ALIGNMENT POINT"))
             C (1- (SSLENGTH A ))
             G (GETINT "GIMME AN INT!...<10>")
             G (IF G G 10)
        );SETQ
      (WHILE (> C -1)
             (SETQ H (SSNAME A C)
                   D (ENTGET  h)
                   C (1- C)
                   pt(trans (cdr(ASSOC G D)) h 1)
                   E (CAR pt)
                   F (SUBST B E pt)
                   F (trans f 1 h)
                   f (cons g f)
                   )
             (ENTMOD (SUBST  F (ASSOC G D) D))
        );WHILE
    'DUN
(TERPRI)
);DEFUN
With a few variations with a few variations you have all the possibilities. I could have written one program to do all the possibilities, but I usually know which I want and I don't want to go through several possibilities to get to the one I want (though I did allow input for the code to align either the 10 or 11 points, or the 15 points in something that uses the 15 point.)

This particular code should be used less than the move command variant as the move command will work on both the 10 and 11 codes where this command will only work on the active one (10 only for left aligned text and 11 only for all other alignments). But for things like lines where I only want to move a point it works  that way as well.

Also if used on Blocks with attributes the blocks will move but the attributes won't. whether that is a good thing depends entirely on your need.

to make it a move only variant I just did this
Code: [Select]
;PROG TO ALIGN X VALUES OF SELECTION SET
(DEFUN C:MX (/ a b c d g m in f e)  ;
                (PRINC "CRITS TO ALIGN...")
       (setvar "cmdecho" 0)
       (SETQ A (SSGET)
             B (CAR (GETPOINT "ALIGNMENT POINT"))
             C (1- (SSLENGTH A ))
             G (GETINT "GIMME AN INT!...<10>")
             G (IF G G 10)
        );SETQ
      (WHILE (> C -1)(PRINC C)
           (SETQ M (SSNAME A C) D (ENTGET M)
                 IN (CDR (ASSOC G D))
                 QQ (TRANS IN 0 1)
                 C (1- C)
                 E (CAR QQ)
                 F  (SUBST B E  QQ))
              (COMMAND "MOVE" M "" QQ F)
        )(setvar "cmdecho" 1);WHILE
    'DUN
(TERPRI)
);DEFUN


pretty much the same thing.

You can also make the "move" a "copy" to copy things in only one direction. I use that to make elevations by picking the appropriate point on the plan xref-ed above.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Looking for align text routine
« Reply #7 on: March 28, 2006, 08:10:04 PM »
Very interesting RbtDanforth, and welcome to the Swamp.
Thanks for sharing.
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.

Crank

  • Water Moccasin
  • Posts: 1503
Re: Looking for align text routine
« Reply #8 on: March 30, 2006, 07:24:51 AM »
This is some code from Mark with some small improvements by me:
Code: [Select]
(defun c:AlignText (/
               ; local functions
               getSegment get-opp-ang undobegin undoend
               ; local variables
               ent txt_ent obj txt_obj obj_typ ang ans SS
               )

  ;;; FUNCTION
  ;;; rotates the user selected (M)TEXT to the user selected
  ;;; entity. valid entites are light weight plines, lines
  ;;; and (m)text. you are given the chance to rotate the
  ;;; by 180 degrees after intial rotation.
  ;;;
  ;;; ARGUMENTS
  ;;; none
  ;;;
  ;;; PLATFORMS
  ;;; 2000+
  ;;;
  ;;; AUTHOR
  ;;; Copyright© 2004 Mark S. Thomas
  ;;; mark_AT_theswamp.org
  ;;;
  ;;; VERSION
  ;;; 1.0 Tue Dec 07, 2004
  ;;; 1.1 Tue Dec 21, 2004  ; added ARC types
  ;;; 1.1a Tue Dec 21, 2004 ; reversed the pick order
  ;;; 1.2 Wen Feb 8, 2006  ; Improved 'Dynamic Input' (by J.J.Damstra)
  ;;; 1.3 Wen Feb 15, 2006 ; Use TORIENT to rotate te text (if possible)
  ;;; 1.4 Wen Feb 15, 2006 ; A previous selection is now possible
  ;;;
  ;;; TODO:
  ;;; handle text that has 'fit' justification
  ;;; add more entites for angle extraction (MLINES !)
  ;;; more testing

  (vl-load-com)

  ;; credit Stig Madsen
  ;; refer to thread titled "relaxed-curves" under the "Teach Me"
  ;; section of TheSwamp at www.theswamp.org/phpBB2/
  (defun getSegment (obj pt / cpt eParam stParam)
    (cond ((setq cpt (vlax-curve-getClosestPointTo obj pt))
           (setq eParam (fix (vlax-curve-getEndParam obj)))
           (if (= eParam (setq stParam (fix (vlax-curve-getParamAtPoint obj cpt))))
             (setq stParam (1- stParam))
             (setq eParam (1+ stParam))
             )
           (list eParam (vlax-curve-getPointAtParam obj stParam)
                 (vlax-curve-getPointAtParam obj eParam))
           )
          )
    )

  ;; undo functions
  (defun undobegin ()
    (vla-EndUndoMark
      (vlax-get-property
        (vlax-get-acad-object)
        'ActiveDocument
        )
      )
    (vla-StartUndoMark
      (vlax-get-property
        (vlax-get-acad-object)
        'ActiveDocument
        )
      )
    )

  (defun undoend ()
    (vla-EndUndoMark
      (vlax-get-property
        (vlax-get-acad-object)
        'ActiveDocument
        )
      )
    )

  ;; returns the oppsite of an angle define in radians
  (defun get-opp-ang (ang)
    (cond ((< ang pi)(+ ang pi))
          ((> ang pi)(- ang pi))
          ((equal ang pi) 0.0)
          ((equal ang 0.0) pi)
          )
    )

  ;; ================= body of main function starts here ======================

  ;;  -----------   Get the Text to Align  -----------------
  (cond
    ((setq txt_ent (car (entsel "\nSelect text to align")))
     (setq txt_obj (vlax-ename->vla-object txt_ent)
           obj_typ (vlax-get-property txt_obj 'ObjectName)
           )
     (cond
       ((or (= obj_typ "AcDbMText") (= obj_typ "AcDbText")))
       (T
         (setq txt_ent nil)
         (alert "Ik kan alleen maar (M)TEXT 'alignen'."))
      )
    )
  )

  ;;  -----------   Get the Object to Align To  -----------------
  (cond
    ((and txt_ent
          (setq ent (entsel "\nSelect entity for alignment: ")))
       (setq obj (vlax-ename->vla-object (car ent))
             obj_typ (vlax-get-property obj 'ObjectName)
       )
       (cond
         ((= obj_typ "AcDbPolyline")
          (if (setq pt_lst (getSegment obj (last ent)))
            (setq ang (angle (cadr pt_lst)(caddr pt_lst)))
            )
          )
         ((= obj_typ "AcDbLine")
          (setq ang (vlax-get-property obj 'Angle))
          )
         ((= obj_typ "AcDbText")
          (setq ang (vlax-get-property obj 'Rotation))
          )
         ((= obj_typ "AcDbMText")
          (setq ang (vlax-get-property obj 'Rotation))
          )
         ((= obj_typ "AcDbArc")
          (setq ang (angle
                      (vlax-safearray->list
                        (vlax-variant-value
                          (vla-get-StartPoint obj)))
                      (vlax-safearray->list
                        (vlax-variant-value
                          (vla-get-EndPoint obj)))
                    )
           )
          )
         
         (T (alert "That's not an entity I deal with"))
       )
     )
  )

  ;;  -----------   Align the Text   -----------------
  (cond
    ((null ang)) ; do nothing
    ((null txt_ent)) ; do nothing
    (T
      (undobegin)
      (vlax-put-property txt_obj 'Rotation ang)
     
      (if (not bns_trot)(if (findfile "acettxt.lsp")(load "acettxt")))
      (if bns_trot
      (progn
; TORIENT gebruiken om de tekst te draaien:
(setq SS (ssadd (vlax-vla-object->ename txt_obj)))
(bns_trot SS nil)
      )
      (progn
(initget 0 "Ja Nee")
(setq ans (getkword "\nTekst 180 graden draaien? [Ja/Nee] <Nee> "))
(if (= ans "Ja")(vlax-put-property txt_obj 'Rotation (get-opp-ang ang)))
)
      )

      ; Om met previous de tekst opnieuw te kunnen selecteren:
      (command "._select" (vlax-vla-object->ename txt_obj) "")
     
      (vlax-release-object txt_obj)
      (undoend)
    )
  )
  (princ)
)
Vault Professional 2023     +     AEC Collection

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: align
« Reply #9 on: March 30, 2006, 07:52:41 AM »
By align, do you mean re-stack w/ correct spacing b/t lines?  I have a way to do it w/ VBA for dtext.  OR do you mean make all left justified and line up in a line vertically/horz ?
I find it hard to believe that Andrea has not answered your basic question.
 That very answer is needed to steer this thread as the two alignment scenarios
 are very different.
 Andrea where are you?
 
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.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Looking for align text routine
« Reply #10 on: March 30, 2006, 08:04:21 AM »
Hi all..

I had somewhere a simple routine to align text and mtext..
but can't find anymore..

is there a way in AutoCAD to do this !?


<Title changed>



Here is one for dtext, by Peter:

Code: [Select]
;;;Written By  : Peter Jamtgaard
(defun C:ATX ()
  (princ "\n* Select Dtext to be Aligned: *")
  (setq SSET (ssget))
  (princ "\n* Enter [V]ertical or [H]orizontal <H>: *")
  (setq PROMPT1 (strcase (substr (getstring) 1 1)))
  (princ "* Pick alignment point: *")
  (setq PT1 (getpoint))
  (if (or (= PROMPT1 "H") (= PROMPT1 ""))
    (setq YLOC   (cadr PT1)
  PROMPT1 "H"
    )
    (setq XLOC   (car PT1)
  PROMPT1 "V"
    )
  )
  (setq C 0)
  (repeat (sslength SSET)
    (setq ENT (ssname SSET C))
    (if (/= ENT nil)
      (progn
(setq ED (entget ENT))
(setq TYPE1 (cdr (assoc 0 ED)))
(if (or (= TYPE1 "INSERT") (= TYPE1 "TEXT"))
  (progn
    (if (= PROMPT1 "H")
      (progn
(setq INSP (cdr (assoc 10 ED)))
(setq YLOC2 (cadr INSP))
(command "move"
ENT
""
"0,0"
(strcat "@0," (rtos (- YLOC YLOC2) 2 4))
)
      )
      (progn (setq INSP (cdr (assoc 10 ED)))
     (setq XLOC2 (car INSP))
     (command
       "move"
       ENT
       ""
       "0,0"
       (strcat "@" (rtos (- XLOC XLOC2) 2 4) ",0")
     )
      )
    )
  )
)
      )
    )
    (setq C (+ C 1))
  )
)

Gary

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Looking for align text routine
« Reply #11 on: March 30, 2006, 08:15:11 AM »
I ended up writing quite a number of align commands depending on the situation.....


Thnaks Bob. Great routines, and I learned something.
By the way welcome to the swamp.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Looking for align text routine
« Reply #12 on: March 30, 2006, 08:20:28 AM »
Here is one I use.
Code: [Select]
(defun c:lu(/ al1 tset0 tset1 al2 al3 alx aly alpt tset2 tlng1 tset3 tset4 al4 al5 al6 tlng2)
; Lines up text
...

Hi Tim, missing value function.
error: no function definition: VALUE

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Looking for align text routine
« Reply #13 on: March 30, 2006, 11:18:48 AM »
Here is one I use.
Code: [Select]
(defun c:lu(/ al1 tset0 tset1 al2 al3 alx aly alpt tset2 tlng1 tset3 tset4 al4 al5 al6 tlng2)
; Lines up text
...

Hi Tim, missing value function.
error: no function definition: VALUE

Gary
Thanks for the info, sorry to all that tried to use mine.  Here is the missing code.
Code: [Select]
(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.

RbtDanforth

  • Guest
Re: Looking for align text routine
« Reply #14 on: March 30, 2006, 03:15:18 PM »


Quote

Thnaks Bob. Great routines, and I learned something.
By the way welcome to the swamp.

Gary
Quote

Thnaks to you as well, Your Dog quote is now a part of my list of comebacks :lmao: