Author Topic: globally change attribute property text width  (Read 1855 times)

0 Members and 1 Guest are viewing this topic.

therealjd

  • Mosquito
  • Posts: 11
globally change attribute property text width
« on: December 22, 2015, 05:52:30 PM »
Hey all,

I need to change all the attribute text properties for all blocks in multiple drawing from whatever width it is, to a width of 1.0
I have the following code that allows me to change attribute properties, but asks to pick a block. i'm hoping to avoid this so i can batch script it on a list of drawings. Could someone help me clean up the code?

Code: [Select]
; Change attribute text angle, height, style, text and width - "EAT" to start
;;;   EAT.LSP            EDIT ATTRIBUTE TEXT            (C)2002, Theodorus Winata
;;;
;;;********** Error Handler **********
(defun
   ERR (X)
  (if (= "Function Cancelled" X)
    (setq X "Ctrl+C or Esc key pressed.")
  ) ;_ end of if
  (setq *ERROR* OLDERR)
  (princ (strcat "\nError: " X))
  (princ)
) ;_ end of defun
;;ERR

;;;********** Main Program **********
(defun
   C:EAT (/ CE CN DT EN NA NE NH NS NT NW OLDERR OP SL SN SS)
  (setq
    OLDERR *ERROR*
    *ERROR* ERR
    CE (getvar "CMDECHO")
    SS (ssget '((0 . "INSERT")))
    CN 0
  ) ;_ end of setq
  ;;setq
  (setvar "CMDECHO" 0)
  (initget "A H S T W")
  (setq
    OP
     (getkword
       "\nChange Attribute (A)ngle/(H)eight/(S)tyle/(T)ext/(W)idth: "
     ) ;_ end of getkword
  ) ;_ end of setq
  (cond
    ((= OP "A")
     (setq NA (getangle "\nNew Text Angle for Attribute: "))
     (if (= NA NIL)
       (setq NA 0)
     ) ;_ end of if
     (if SS
       (repeat (setq SL (sslength SS))
         (setq
           SN (ssname SS CN)
           NE (entnext SN)
         ) ;_ end of setq
         ;;setq
         (while (and
                  NE
                  (/= (setq EN (cdr (assoc 0 (setq DT (entget NE)))))
                      "SEQEND"
                  ) ;_ end of /=
                ) ;_ end of and
           (if (= EN "ATTRIB")
             (progn
               (setq DT (subst (cons 50 NA) (assoc 50 DT) DT))
               (entmod DT)
               (entupd SN)
             ) ;_ end of progn
             ;;progn
           ) ;_ end of if
           ;;if
           (setq NE (entnext NE))
         ) ;_ end of while
         ;;while
         (setq CN (1+ CN))
         (repeat 25 (princ "\010"))
         (princ (strcat "Total " (itoa CN) " done of " (itoa SL)))
       ) ;_ end of repeat
       ;;repeat
       (princ "\nNo input")
     ) ;_ end of if
     ;;if
    )
    ;;A
    ((= OP "H")
     (setq NH (getreal "\nNew Text Height for Attribute: "))
     (if SS
       (repeat (setq SL (sslength SS))
         (setq
           SN (ssname SS CN)
           NE (entnext SN)
         ) ;_ end of setq
         ;;setq
         (while (and
                  NE
                  (/= (setq EN (cdr (assoc 0 (setq DT (entget NE)))))
                      "SEQEND"
                  ) ;_ end of /=
                ) ;_ end of and
           (if (= EN "ATTRIB")
             (progn
               (setq DT (subst (cons 40 NH) (assoc 40 DT) DT))
               (entmod DT)
               (entupd SN)
             ) ;_ end of progn
             ;;progn
           ) ;_ end of if
           ;;if
           (setq NE (entnext NE))
         ) ;_ end of while
         ;;while
         (setq CN (1+ CN))
         (repeat 25 (princ "\010"))
         (princ (strcat "Total " (itoa CN) " done of " (itoa SL)))
       ) ;_ end of repeat
       ;;repeat
       (princ "\nNo input")
     ) ;_ end of if
     ;;if
    )
    ;;H
    ((= OP "S")
     (setq NS (getstring "\nNew Text Style for Attribute: "))
     (if SS
       (repeat (setq SL (sslength SS))
         (setq
           SN (ssname SS CN)
           NE (entnext SN)
         ) ;_ end of setq
         ;;setq
         (while (and
                  NE
                  (/= (setq EN (cdr (assoc 0 (setq DT (entget NE)))))
                      "SEQEND"
                  ) ;_ end of /=
                ) ;_ end of and
           (if (= EN "ATTRIB")
             (progn
               (setq DT (subst (cons 7 NS) (assoc 7 DT) DT))
               (entmod DT)
               (entupd SN)
             ) ;_ end of progn
             ;;progn
           ) ;_ end of if
           ;;if
           (setq NE (entnext NE))
         ) ;_ end of while
         ;;while
         (setq CN (1+ CN))
         (repeat 25 (princ "\010"))
         (princ (strcat "Total " (itoa CN) " done of " (itoa SL)))
       ) ;_ end of repeat
       ;;repeat
       (princ "\nNo input")
     ) ;_ end of if
     ;;if
    )
    ;;S
    ((= OP "T")
     (setq NT (getstring "\nNew Text for Attribute: "))
     (if SS
       (repeat (setq SL (sslength SS))
         (setq
           SN (ssname SS CN)
           NE (entnext SN)
         ) ;_ end of setq
         ;;setq
         (while (and
                  NE
                  (/= (setq EN (cdr (assoc 0 (setq DT (entget NE)))))
                      "SEQEND"
                  ) ;_ end of /=
                ) ;_ end of and
           (if (= EN "ATTRIB")
             (progn
               (setq DT (subst (cons 1 NT) (assoc 1 DT) DT))
               (entmod DT)
               (entupd SN)
             ) ;_ end of progn
             ;;progn
           ) ;_ end of if
           ;;if
           (setq NE (entnext NE))
         ) ;_ end of while
         ;;while
         (setq CN (1+ CN))
         (repeat 25 (princ "\010"))
         (princ (strcat "Total " (itoa CN) " done of " (itoa SL)))
       ) ;_ end of repeat
       ;;repeat
       (princ "\nNo input")
     ) ;_ end of if
     ;;if
    )
    ;;T
    ((= OP "W")
     (setq NW (getreal "\nNew Text Width for Attribute: "))
     (if SS
       (repeat (setq SL (sslength SS))
         (setq
           SN (ssname SS CN)
           NE (entnext SN)
         ) ;_ end of setq
         ;;setq
         (while (and
                  NE
                  (/= (setq EN (cdr (assoc 0 (setq DT (entget NE)))))
                      "SEQEND"
                  ) ;_ end of /=
                ) ;_ end of and
           (if (= EN "ATTRIB")
             (progn
               (setq DT (subst (cons 41 NW) (assoc 41 DT) DT))
               (entmod DT)
               (entupd SN)
             ) ;_ end of progn
             ;;progn
           ) ;_ end of if
           ;;if
           (setq NE (entnext NE))
         ) ;_ end of while
         ;;while
         (setq CN (1+ CN))
         (repeat 25 (princ "\010"))
         (princ (strcat "Total " (itoa CN) " done of " (itoa SL)))
       ) ;_ end of repeat
       ;;repeat
       (princ "\nNo input")
     ) ;_ end of if
     ;;if
    )
    ;;W
  ) ;_ end of cond
  ;;cond
  (setvar "CMDECHO" CE)
  (setq *ERROR* OLDERR)
  (princ)
) ;_ end of defun
(C:EAT)

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: globally change attribute property text width
« Reply #1 on: December 22, 2015, 06:57:01 PM »
Try the following, quickly written:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:attw ( / e i s x )
  2.     (if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1))))
  3.         (repeat (setq i (sslength s))
  4.             (setq e (entnext (ssname s (setq i (1- i))))
  5.                   x (entget e)
  6.             )
  7.             (while (= "ATTRIB" (cdr (assoc 0  x)))
  8.                 (or (equal 1.0 (cdr (assoc 41 x)) 1e-8)
  9.                     (entmod (subst '(41 . 1.0) (assoc 41 x) x))
  10.                 )
  11.                 (setq e (entnext e)
  12.                       x (entget  e)
  13.                 )
  14.             )
  15.         )
  16.     )
  17.     (princ)
  18. )

therealjd

  • Mosquito
  • Posts: 11
Re: globally change attribute property text width
« Reply #2 on: December 22, 2015, 07:21:07 PM »
Lee! Brilliant. tested on a couple drawings, works wonderfully.

Thanks so much!

Jd...

Try the following, quickly written:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:attw ( / e i s x )
  2.     (if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1))))
  3.         (repeat (setq i (sslength s))
  4.             (setq e (entnext (ssname s (setq i (1- i))))
  5.                   x (entget e)
  6.             )
  7.             (while (= "ATTRIB" (cdr (assoc 0  x)))
  8.                 (or (equal 1.0 (cdr (assoc 41 x)) 1e-8)
  9.                     (entmod (subst '(41 . 1.0) (assoc 41 x) x))
  10.                 )
  11.                 (setq e (entnext e)
  12.                       x (entget  e)
  13.                 )
  14.             )
  15.         )
  16.     )
  17.     (princ)
  18. )

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: globally change attribute property text width
« Reply #3 on: December 22, 2015, 07:27:02 PM »
You're welcome Jd, glad it helps!