Jump to content
dnovember99

aligning text within text editor.

Recommended Posts

dnovember99

so i have been looking for some time now to try and find something that will be able to help me with this. i want to be and to have the text within Mtext to be aligned right, center or left. the only way that i can see to do that right now is to double click, highlight the text and then selection it from the ribbon.

 

i have tried to use textalign command and that just doesnt seem to move the text to the right, center or left.

 

anyone know of a lisp out there that you would be able to just choose left, right or center and then click the text that you want to change?

 

thank you all

2018-05-11 09_43_29-Autodesk AutoCAD 2016 - [J__Phoenix_Programs_Sprouts_1750001733 Sprouts Farm.png

2018-05-11 09_43_43-Autodesk AutoCAD 2016 - [J__Phoenix_Programs_Sprouts_1750001733 Sprouts Farm.png

Share this post


Link to post
Share on other sites
ronjonp

All you need to do is toggle justify in the properties palette ?

Share this post


Link to post
Share on other sites
dnovember99

yes, i just am the type that doesnt like using the palette. just thought i would see if there is something out there that could make things a little faster

Share this post


Link to post
Share on other sites
ronjonp
yes, i just am the type that doesnt like using the palette. just thought i would see if there is something out there that could make things a little faster

 

Fair enough .. I'll hammer out some code in a bit if someone else does not jump in :)

Share this post


Link to post
Share on other sites
dnovember99

oh awesome! the other thing that i am not a fan of with using that palette is if you have Mtext and dont have the box out to a certain size when you do hit justify from right to left it moves the text. so that is another extra step. not sure if that can be considered also or not. if not all good. just thought that i would throw it out there.

Share this post


Link to post
Share on other sites
Lee Mac
Posted (edited)

Try this:

(defun c:mj ( / g i l s )
   (if (setq s (ssget "_:L" '((0 . "MTEXT"))))
       (progn
           (repeat (setq i (sslength s))
               (setq l (cons (entget (ssname s (setq i (1- i)))) l))
           )
           (princ "\nAlter the alignment using the numberpad <done>: ")
           (while (and (= 2 (car (setq g (grread nil 2)))) (< 48 (cadr g) 58))
               (setq g (cons 71 (cdr (assoc (cadr g) '((49 . 7)(50 . (51 . 9)(52 . 4)(53 . 5)(54 . 6)(55 . 1)(56 . 2)(57 . 3))))))
               (foreach x l (entmod (subst g (assoc 71 x) x)))
           )
       )
   )
   (princ)
)

 

mtextjustification.gif

Edited by Lee Mac

Share this post


Link to post
Share on other sites
ronjonp
Posted (edited)

Nice Lee :) .. here's another quick one.

(defun c:just (/ j k s)
 (setq j '("TL" "TC" "TR" "ML" "MC" "MR" "BL" "BC" "BR"))
 (initget 0 (apply 'strcat (mapcar '(lambda (x) (strcat x " ")) j)))
 (cond
   ((and (or (setq
	k (getkword
	    (strcat "\n[" (apply 'strcat (mapcar '(lambda (x) (strcat x "/")) j)) "]: <TL>")
	  )
      )
      (setq k "TL")
  )
  (setq s (ssget ":L" '((0 . "mtext"))))
    )
    (foreach e	(vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (vla-put-attachmentpoint (vlax-ename->vla-object e) (1+ (vl-position k j)))
    )
   )
 )
 (princ)
)
(vl-load-com)

Edited by ronjonp
*added all justification options

Share this post


Link to post
Share on other sites
dnovember99
Try this:
(defun c:mj ( / g i l s )
   (if (setq s (ssget "_:L" '((0 . "MTEXT"))))
       (progn
           (repeat (setq i (sslength s))
               (setq l (cons (entget (ssname s (setq i (1- i)))) l))
           )
           (princ "\nAlter the alignment using the numberpad <done>: ")
           (while (and (= 2 (car (setq g (grread nil 2)))) (< 48 (cadr g) 58))
               (setq g (cons 71 (cdr (assoc (cadr g) '((49 . 7)(50 . (51 . 9)(52 . 4)(53 . 5)(54 . 6)(55 . 1)(56 . 2)(57 . 3))))))
               (foreach x l (entmod (subst g (assoc 71 x) x)))
           )
       )
   )
   (princ)
)

 

Mr. Mac, thank you for this. i was playing around with it and i noticed that on the key pad (9)is bottom (6) center and (3) top and then the other side (7) bottom (4) center and (1) top.

 

i think that is to where you want to have the leader showing at. am i thinking correctly? i was thinking more along the lines of when you double click on the text, highlight the text and while in text editor just above "paragraph" you can select the "justify" right, left, center, etc.

 

i was talking with someone and they told me that just using a macro could work. here is what i was given.

 

;; Justification Macros


(defun _justifyIt (justify title / ss)
 (princ (strcat "\nSelect *Text to " title " justify: "))
 (if (setq ss (ssget "_:L" '((0 . "ATTDEF,MTEXT,TEXT"))))
   (command "_.justifytext" ss "" justify)
 )
 (princ)
)

(defun c:JL (/) (_justifyIt "_L" "Left"))
(defun c:JR (/) (_justifyIt "_R" "Right"))

 

i am noticing that this doesnt work on all mtext. it depends on the justification point it has. and/or it will only work when the text is looking like this. i sure hope that i am making sense with this.

2018-05-11 10_56_15-Autodesk AutoCAD 2016 - [J__Phoenix_Programs_Sprouts_1750001733 Sprouts Farm.png

Share this post


Link to post
Share on other sites
Lee Mac

Good stuff Ron :thumbsup:

Share this post


Link to post
Share on other sites
ronjonp
Good stuff Ron :thumbsup:

 

Cheers! :)

Share this post


Link to post
Share on other sites
tombu

You could add JT as an alias to JUSTIFYTEXT in Acad.pgp using the ALIASEDIT Express Tool or make a Ctrl+J Shortcut Key for it under Keyboard Shortcuts in the CUI

 

One more option is to add a 'Justify Text' flyout to both 'Mtext Object Menu' and 'Mtext Objects Menu' Under 'Shortcut Menus' in the CUI with commands for each option like:

Name TL

Macro

$M=$(if,$(eq,$(substr,$(getvar,cmdnames),1,4),GRIP),_justifytext;TL;,^C^C_justifytext;TL)  

and another Justify Text flyout to both 'Text Object Menu' and 'Text Objects Menu' Under 'Shortcut Menus' in the CUI with commands for each option like:

Name Left

Macro

$M=$(if,$(eq,$(substr,$(getvar,cmdnames),1,4),GRIP),_justifytext;TL;,^C^C_justifytext;Left)  

 

I can use the shortcut Ctrl+J, enter JT, or right-click selected text and pick 'Justify Text' to select the justification.

Share this post


Link to post
Share on other sites
Lee Mac
Mr. Mac, thank you for this. i was playing around with it and i noticed that on the key pad (9)is bottom (6) center and (3) top and then the other side (7) bottom (4) center and (1) top.

 

You should find that the justification is set as follows: 7=Top-Left, 8=Top-Center, 9=Top-Right, 4=Middle-Left, 5=Middle-Center, 6=Middle-Right, 1=Bottom-Left etc.

 

This is confirmed in my testing - is this not the case?

Share this post


Link to post
Share on other sites
rlx
You should find that the justification is set as follows: 7=Top-Left, 8=Top-Center, 9=Top-Right, 4=Middle-Left, 5=Middle-Center, 6=Middle-Right, 1=Bottom-Left etc.

 

This is confirmed in my testing - is this not the case?

 

 

Numeric layouts can differ. At my work couple of colleagues are from Belgium and they prefer their own keyboard layout so having to type something on their keybord is well, challenging to say the least. But nice little routine, both from you and ronjonp.

Share this post


Link to post
Share on other sites
dober

@ Lee

If that were synonymous with text, now it works only with MTexte

 

Würde das auch mit Text gehen, jetzt funktioniert das nur mit MTexte

:D

Share this post


Link to post
Share on other sites
Lee Mac
@ Lee

If that were synonymous with text, now it works only with MTexte

 

The following should work with both -

(defun c:mj ( / g i k l s )
   (setq k
      '(
           (49 ((71 . 7)) ((72 . 0) (73 . 1)))
           (50 ((71 . ) ((72 . 1) (73 . 1)))
           (51 ((71 . 9)) ((72 . 2) (73 . 1)))
           (52 ((71 . 4)) ((72 . 0) (73 . 2)))
           (53 ((71 . 5)) ((72 . 1) (73 . 2)))
           (54 ((71 . 6)) ((72 . 2) (73 . 2)))
           (55 ((71 . 1)) ((72 . 0) (73 . 3)))
           (56 ((71 . 2)) ((72 . 1) (73 . 3)))
           (57 ((71 . 3)) ((72 . 2) (73 . 3)))
       )
   )
   (if (setq s (ssget "_:L" '((0 . "TEXT,MTEXT"))))
       (progn
           (repeat (setq i (sslength s))
               (setq i (1- i)
                     x (entget (ssname s i))
               )
               (if (and (= "TEXT" (cdr (assoc 0 x))) (= 0 (cdr (assoc 72 x)) (cdr (assoc 73 x))))
                   (entmod (setq x (subst (cons 11 (cdr (assoc 10 x))) (assoc 11 x) x)));  (subst '(73 . 1) '(73 . 0) x)))
               )
               (setq l (cons x l))
           )
           (princ "\nAlter the alignment using the numberpad <done>: ")
           (while (and (= 2 (car (setq g (grread nil 2)))) (< 48 (cadr g) 58))
               (setq g (cdr (assoc (cadr g) k)))
               (foreach x l
                   (foreach y (if (= "MTEXT" (cdr (assoc 0 x))) (car g) (cadr g))
                       (setq x (subst y (assoc (car y) x) x))
                   )
                   (entmod x)
               )
           )
       )
   )
   (princ)
)

Share this post


Link to post
Share on other sites
dober

Thank you perfect LEE

As always tooles Lisp :notworthy:

 

Danke perfekt LEE

Wie immer tooles Lisp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×