ILoveMadoka 发表于 2022-7-6 17:10:23

Text - Justification Routine H

This works with one caveat. It moves the text to 0,0.
Can someone help me modify this code to work correctly?
ie: NOT moving the text!
(re-adjusting it a bit is fine, moving off screen is a PITA!!)
It only works with TEXT as well. Not a real problem but..
 
Thanks!
 
;------------------ CODE ---------------------------------
 
(defun C:JMR ()
(setq t (ssget))
(prompt "\nSet to Middle Right Justification . . .")
(setq j1 "MR")
(setq m (sslength t)
      index 0)
(repeat m
    (setq a (entget (ssname t index))
          p (cdr (assoc 0 a)))
    (if (= p "TEXT")
      (progn
         (setq j(assoc 72 a)
               j2 (assoc 73 a)
               p(assoc 10 a)
               q(assoc 11 a)
               j0 (cdr j))
      (progn
         (setq q1 (cdr q)
               p1 (cons (car p) q1)
               n1 (subst p1 p a))
             )      
         (setq n(subst '(72 . 2) j n1))
         (setq n(subst '(73 . 2) j2 n))
         (entmod n)
      )
    )
    (setq index (+ index 1))
))

chauncy274 发表于 2022-7-6 17:40:55

If you're using 2009, why can't you just use the tjust command?

ILoveMadoka 发表于 2022-7-6 17:54:13

I use 3 justifications for the most part and it's easier to type a 2-3 letter command instead of having to select objects, hit enter, enter the justification and hit enter.
 
I could just script it but I like coding and am still learning
so solving the problem via code is half the fun.
 
There are people on here lightyears ahead of me in their knowledge and I like seeing their methods.. (Thanks guys!)
I'm wanting to learn more about coding in autolisp..

Lee Mac 发表于 2022-7-6 18:17:53

Hi ILoveMadoka,
 
Hopefully this LISP will do the job
 

(defun C:JMR (/ ss1 sslen index tents ent1 enttyp bspt1)   (setq ss1 (ssget))   (setq sslen (sslength ss1)      index 0       tents 0   ) ; end setq   (repeat sslen       (setq   ent1 (entget (ssname ss1 index))         enttyp (cdr (assoc 0 ent1))       ) ; end setq       (if (= enttyp "TEXT")         (progn               (setq bspt1 (cdr (assoc 10 ent1)))               (setq ent1 (subst (cons 11 bspt1) (assoc 11 ent1) ent1))               (entmod ent1)               (setq ent1 (subst (cons 72 2) (assoc 72 ent1) ent1))               (setq ent1 (subst (cons 73 2) (assoc 73 ent1) ent1))               (entmod ent1)               (setq tents (+ tents 1))         ) ; end progn       ) ; end if       (setq index (+ index 1))   ) ; end repeat   (if (/= tents 1)   (alert (strcat (itoa tents) " Text Entities Modified."))   (alert (strcat (itoa tents) " Text Entity Modified. "))   ) ; end if   (princ)) ; end defunLet me know if this is what you were after
页: [1]
查看完整版本: Text - Justification Routine H