Author Topic: Change text justification with moving text  (Read 170 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 305
Change text justification with moving text
« on: September 11, 2019, 12:23:40 PM »
Hello,

I have some text justified to the right, I wish to change the justification of the text to the left.
I want the text to move, ie. not retain its position, as if you had changed the text justification using the properties dialogue box.

I have tried changing dxf codes to (72 . 0) (73 . 1) but the text retains it's position, the same if you use tjust.

Cad file atatched, which should explain what I'm trying to do.

this is the lisp bolted together so far.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:MC100 (/ ss1)
  2. (c:REMSPCMC)
  3. (setq ss1 (ssget "X" '((0 . "TEXT") (8 . "Comments"))))
  4.                 (command "_.move" ss1 "" "_non" '(0.0 0.0 0.0) "_non" '(0.245 0.250 0.0))
  5. ;;              (command "_.justifytext" ss1 "" "L")
  6. (c:JBL)
  7.                 (command "_.chprop" ss1 "" "_LA" "TEXT" "")
  8.         (princ)
  9.         )
  10.  
  11.  
  12. ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/remove-blank-spaces-from-beginning-and-end-of-a-text-string/td-p/832272
  13. (defun C:REMSPCMC (/ ss i elist txt)
  14. (setq ss (ssget "X" '((0 . "TEXT")(8 . "Comments"))))
  15. (if ss
  16. (setq i (1- (sslength ss)))
  17. (while (>= i 0)
  18. (setq elist (entget (ssname ss i))
  19. txt (vl-string-trim " " (cdr (assoc 1 elist)))
  20. i (1- i)
  21. )
  22. (entmod (subst (cons 1 txt)(assoc 1 elist) elist))
  23. )
  24. )
  25. (alert "No TEXT selected.")
  26. )
  27. )
  28.  
  29.  
  30. (defun C:JBL (/ ss1 sslen index ent1 enttyp bspt1)
  31. (prompt "\nSet to Left Justification . . .")
  32.    (setq ss1 (ssget "X" '((0 . "TEXT") (8 . "Comments"))))
  33.    (setq     sslen (sslength ss1)
  34.              index 0
  35.              tents 0
  36.    ) ; end setq
  37.    (repeat sslen
  38.        (setq    
  39.            ent1 (entget (ssname ss1 index))
  40.            enttyp (cdr (assoc 0 ent1))
  41.        ) ; end setq
  42. (if (= enttyp "MTEXT")
  43.       (progn
  44.         (Command "Explode" ss1)
  45.           (alert "Text was MTEXT! Rerun the command. ")
  46.       )
  47. )
  48.        (if (= enttyp "TEXT")
  49.            (progn
  50.                (setq bspt1 (cdr (assoc 10 ent1)))
  51.                (setq ent1 (subst (cons 11 bspt1) (assoc 11 ent1) ent1))
  52.                (entmod ent1)
  53.                (setq ent1 (subst (cons 72 0) (assoc 72 ent1) ent1))
  54.                (setq ent1 (subst (cons 73 0) (assoc 73 ent1) ent1))
  55.                (entmod ent1)
  56.                (setq tents (+ tents 1))
  57.            ) ; end progn
  58.        ) ; end if
  59.        (setq index (+ index 1))
  60.    ) ; end repeat
  61.  
  62.    (princ)
  63. ) ; end defun

Thanks

ribarm

  • Water Moccasin
  • Posts: 2123
  • Marko Ribar, architect
Re: Change text justification with moving text
« Reply #1 on: September 11, 2019, 12:47:55 PM »
This will never happen :

(if (= enttyp "MTEXT")
      (progn
        (Command "Explode" ss1)
          (alert "Text was MTEXT! Rerun the command. ")
      )
)

Because of this selection set filter :

(setq ss1 (ssget "X" '((0 . "TEXT") (8 . "Comments"))))

And beside all this, command EXPLODE won't work on selection sets through routine unless you temporarily set undocumented sys var QAFLAGS = 1...

After all you said that you want to achieve setting text properties like through properties pallete, so why not use pallete if its working well... Tell us why do you need ALISP version of this, what do you want to achieve and you need routine for this...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

didier

  • Newt
  • Posts: 28
  • expatrié
Re: Change text justification with moving text
« Reply #2 on: September 11, 2019, 12:54:18 PM »
erreur de ma part...
eternal beginner ...
my english is not fluent ...

Pad

  • Bull Frog
  • Posts: 305
Re: Change text justification with moving text
« Reply #3 on: September 11, 2019, 12:56:55 PM »
Hi Ribarm,

Thanks for your reply.  That it all uncessary code form a lisp I'm bolting on, so don't worry about that.

After all you said that you want to achieve setting text properties like through properties pallete, so why not use pallete if its working well... Tell us why do you need ALISP version of this, what do you want to achieve and you need routine for this...  Because it's one step of a few steps I want to have automated in Lisp.

The atached DWG shows what i'm trying to acheive, everything is fine except changing the text justification and having the text move accordingly.

Regards
Patrick

ribarm

  • Water Moccasin
  • Posts: 2123
  • Marko Ribar, architect
Re: Change text justification with moving text
« Reply #4 on: September 11, 2019, 01:29:35 PM »
This works on my side (changing text position with justification point) :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:txt-bl-br+br-bl ( / txt txtd )
  2.   (while
  3.     (or
  4.       (not (setq txt (car (entsel "\nPick TEXT with BL or BR justification..."))))
  5.       (if txt
  6.         (/= (cdr (assoc 0 (setq txtd (entget txt)))) "TEXT")
  7.       )
  8.     )
  9.     (prompt "\nMissed, or picked wrong entity type...")
  10.   )
  11.   (cond
  12.     ( (= (cdr (assoc 72 txtd)) 0)
  13.       (setq txtd (subst '(72 . 2) '(72 . 0) txtd))
  14.     )
  15.     ( (= (cdr (assoc 72 txtd)) 2)
  16.       (setq txtd (subst '(72 . 0) '(72 . 2) txtd))
  17.     )
  18.   )
  19.   (entupd (cdr (assoc -1 (entmod txtd))))
  20.   (princ)
  21. )
  22.  

HTH.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Pad

  • Bull Frog
  • Posts: 305
Re: Change text justification with moving text
« Reply #5 on: September 11, 2019, 01:46:55 PM »
Thanks Ribarm.   I will give that a go once I've fed the kids.

Cheers
P

Lee Mac

  • Seagull
  • Posts: 12255
  • London, England
Re: Change text justification with moving text
« Reply #6 on: September 11, 2019, 01:49:13 PM »
I think the following should perform all of the operations you require -
Code - Auto/Visual Lisp: [Select]
  1. (defun c:fixtext ( / i s x )
  2.     (if (setq s (ssget "_:L" '((0 . "TEXT"))))
  3.         (repeat (setq i (sslength s))
  4.             (setq i (1- i)
  5.                   x (entget (ssname s i))
  6.             )
  7.             (entmod
  8.                 (subst (cons 11 (mapcar '+ (cdr (assoc (if (= 0 (cdr (assoc 72 x)) (cdr (assoc 73 x))) 10 11) x)) '(0.245 0.25 0.0))) (assoc 11 x)
  9.                     (subst (cons 1 (vl-string-trim " " (cdr (assoc 1 x)))) (assoc 1 x)
  10.                         (subst '(73 . 1) (assoc 73 x)
  11.                             (subst '(72 . 0) (assoc 72 x) x)
  12.                         )
  13.                     )
  14.                 )
  15.             )
  16.         )
  17.     )
  18.     (princ)
  19. )

Pad

  • Bull Frog
  • Posts: 305
Re: Change text justification with moving text
« Reply #7 on: September 11, 2019, 02:18:06 PM »
Wow thats amazing, a thing of beauty.
Works perfectly, thanks Lee.
These texts are short annotations done in the field, I then use your BFIND lisp on the text.

Thank you very much!

P

Lee Mac

  • Seagull
  • Posts: 12255
  • London, England
Re: Change text justification with moving text
« Reply #8 on: September 11, 2019, 04:26:50 PM »
Good stuff - you're welcome.