Author Topic: Help:Align Text,Mtext to vertical liine  (Read 1156 times)

0 Members and 1 Guest are viewing this topic.

mhy3sx

  • Newt
  • Posts: 115
Help:Align Text,Mtext to vertical liine
« on: May 21, 2023, 02:17:34 PM »
Hi. I am using this old code to align Mtext  (midle center) to vetical line. I want to update the code to wotk for text and Text. For Mtext works fine.
Can any one help?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test(/ l ss i sn v p e)
  2.   (if (and (setq l (car (entsel "\n Select Line :")))
  3.            (eq (cdr (assoc 0 (entget l))) "LINE")
  4.            (progn
  5.              (prompt "select MText ")
  6.              (setq ss (ssget "_:L" '((0 . "MTEXT"))))
  7.            )
  8.       )
  9.     (repeat (setq i (sslength ss))
  10.       (setq sn (ssname ss (setq i (1- i))))
  11.       (setq v (vlax-ename->vla-object sn))
  12.                 l
  13.                 (cdr (assoc 10 (entget sn)))
  14.               )
  15.       )
  16.        (if  (eq (cdr (assoc 0 (setq e (entget sn)))) "MTEXT")
  17.         (progn
  18.           (entmod (subst (cons 71 5) (assoc 71 e) e))
  19.           (vla-put-insertionpoint v (vlax-3d-point p))
  20.         )
  21.         (progn
  22.           (vla-put-alignment v acAlignmentMiddleCenter)
  23.         )
  24.       )
  25.     )
  26.   )
  27.   (princ)
  28. )
  29.  
  30.  

Thanks

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Help:Align Text,Mtext to vertical liine
« Reply #1 on: May 21, 2023, 03:12:14 PM »
Have you tried changing this :
Code: [Select]
...
           (progn
             (prompt "select MText ")
             (setq ss (ssget "_:L" '((0 . "MTEXT"))))
           )
...
To :
Code: [Select]
...
           (progn
             (prompt "\nSelect MText or Text")
             (setq ss (ssget "_:L" '((0 . "*TEXT"))))
           )
...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

mhy3sx

  • Newt
  • Posts: 115
Re: Help:Align Text,Mtext to vertical liine
« Reply #2 on: May 21, 2023, 04:00:49 PM »
Hi ribam. Thanks for the help. The code works now but this line is correct ?

Code - Auto/Visual Lisp: [Select]
  1.        (if  (eq (cdr (assoc 0 (setq e (entget sn)))) "MTEXT")
  2.         (progn
  3.           (entmod (subst (cons 71 5) (assoc 71 e) e))
  4.           (vla-put-insertionpoint v (vlax-3d-point p))
  5.         )
  6.  
  7.  


Thanks

mhy3sx

  • Newt
  • Posts: 115
Re: Help:Align Text,Mtext to vertical liine
« Reply #3 on: May 30, 2023, 09:45:53 AM »
Hi, I am trying to align now to align text ,mtest to vertical line at the right. The problem is the texts are reversed . how to fix it?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:AtclR (/ l ss i sn v p e)
  2.   (if (and (setq l (car (entsel "\n Select Line :")))
  3.            (eq (cdr (assoc 0 (entget l))) "LINE")
  4.            (progn
  5.              (prompt "Select TEXT,MTEXT")
  6.              (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
  7.            )
  8.       )
  9.     (repeat (setq i (sslength ss))
  10.       (setq sn (ssname ss (setq i (1- i))))
  11.       (setq v (vlax-ename->vla-object sn))
  12.                 l
  13.                 (cdr (assoc 10 (entget sn)))
  14.               )
  15.       )
  16.        (if (or (eq (cdr (assoc 0 (setq e (entget sn)))) "TEXT") (eq (cdr (assoc 0 (setq e (entget sn)))) "MTEXT"))
  17.         (progn
  18.            (entmod (subst (cons 71 3) (assoc 71 e) e))
  19.           (vla-put-insertionpoint v (vlax-3d-point p))
  20.         )
  21.         (progn
  22.           (vla-put-alignment v acAlignmentMiddleCenter)
  23.         )
  24.       )
  25.     )
  26.   )
  27.   (princ)
  28. )
  29.  
  30.  

Thanks

ScottMC

  • Newt
  • Posts: 191
Re: Help:Align Text,Mtext to vertical liine
« Reply #4 on: May 30, 2023, 11:19:48 AM »
Oops.. correction: 1 = left

Handy tool for sure. Thanks "mhy3sx"
line 21:
      (progn                                  \/ - the 3 = right justify | 5 = cen | 1 = left <<
           (entmod (subst (cons 71 1) (assoc 71 e) e))
          (vla-put-insertionpoint v (vlax-3d-point p))
        )

I decided to delete the line aligned to with..
line: 29 *before the (princ)* - (entdel l)
« Last Edit: May 30, 2023, 12:06:46 PM by ScottMC »

mhy3sx

  • Newt
  • Posts: 115
Re: Help:Align Text,Mtext to vertical liine
« Reply #5 on: May 30, 2023, 03:54:00 PM »
Hi ScottMC . I ask to align the text to the right not to left. Is any solution to this problem?
Look the attach file.

Thanks

ScottMC

  • Newt
  • Posts: 191
Re: Help:Align Text,Mtext to vertical liine
« Reply #6 on: May 30, 2023, 05:00:57 PM »
Doesn't the (cons 71 3)(assoc.. work?

mhy3sx

  • Newt
  • Posts: 115
Re: Help:Align Text,Mtext to vertical liine
« Reply #7 on: May 30, 2023, 05:34:27 PM »
(cons 71 3) is for right.
(cons 71 1) is for left but reverse the text.

look the attach file. If you find a solution post all the code

Thanks

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Help:Align Text,Mtext to vertical liine
« Reply #8 on: May 30, 2023, 05:55:49 PM »
Something like this ?
Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ col int sel int ent get grp vla ins )
  2.   ;;----------------------------------------------------;;
  3.   ;;    Author : Tharwat Al Choufi                      ;;
  4.   ;; website: https://autolispprograms.wordpress.com    ;;
  5.   ;;----------------------------------------------------;;
  6.   (and (setq col (car (entsel "\nSelect line to align and justify texts to < TopRight > : ")))
  7.        (or (= (cdr (assoc 0 (entget col))) "LINE")
  8.            (alert "Must select LINE object only. Try again")
  9.            )
  10.        (princ "\nSelect Text or Mtext objects :")
  11.        (setq int -1 sel (ssget "_:L" '((0 . "*TEXT"))))
  12.        (while (setq int (1+ int) ent (ssname sel int))
  13.          (and (setq get (entget ent))
  14.               (or (and (= (cdr (assoc 0 get)) "TEXT")
  15.                        (setq grp '((71 . 0) (72 . 2) (73 . 3)))
  16.                        )
  17.                   (setq grp '((71 . 3) (72 . 5) (73 . 1)))
  18.                   )
  19.               (entmod (append (entmod (subst (cons 11 (cdr (assoc 10 get))) (assoc 11 get) get)) grp))
  20.               (or (vla-getboundingbox (setq vla (vlax-ename->vla-object ent)) 'lft 'rgt)
  21.                   (setq ins (vlax-safearray->list rgt))
  22.                   )
  23.               (vlax-invoke vla 'Move ins (vlax-curve-getclosestpointto col ins))
  24.               )
  25.          )
  26.        )
  27.   (princ)
  28.  

mhy3sx

  • Newt
  • Posts: 115
Re: Help:Align Text,Mtext to vertical liine
« Reply #9 on: May 31, 2023, 02:35:12 AM »
Thank you Tharwat. Now is working perfect !!!

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Help:Align Text,Mtext to vertical liine
« Reply #10 on: May 31, 2023, 03:36:37 AM »
Excellent, you're welcome anytime.