home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 6.img / BONUS1.LIB / ATTREDEF.LSP < prev    next >
Encoding:
Text File  |  1993-02-08  |  11.3 KB  |  337 lines

  1. ;;;--------------------------------------------------------------------------;
  2. ;;; ATTREDEF.LSP
  3. ;;;   ¬⌐┼v (C) 1988-1992  Autodesk ñ╜Ñq
  4. ;;;
  5. ;;;   Ñ╗╡{ªíñwÑ╤ Autodesk ñ╜Ñq╡∙ÑU¬⌐┼v, ╢╚⌐≤ñU¡z▒í¬pñUÑi▒┬╗P▒zíu│\ÑiívíC
  6. ;;;   ╗╒ñUñú▒oÑHÑ⌠ª≤º╬ªí╡oªµ⌐╬ÑX¬⌐ª╣╡{ªí¬║íu¡∞⌐l╜Xív; ª²ñ╣│\▒zªb»S⌐w¡lÑ═
  7. ;;;   ¬║ñuº@ñW╡▓ªXª╣╡{ªí¬║íuÑ╪¬║╜Xív¿╧Ñ╬íCª│├÷│o├■¡lÑ═ñuº@¬║▒°Ñ≤ªpñU:
  8. ;;;
  9. ;;;   ( i)  │]¡pñW╗Pñuº@ñW¼╥»┬║Θ░w╣∩ Autodesk ñ╜Ñq¬║▓ú½~íC
  10. ;;;   (ii)  ╕ⁿª│íu¬⌐┼v  (C) 1988-1992  Autodesk ñ╜Ñqív¬║¬⌐┼v│qºiíC
  11. ;;;
  12. ;;;
  13. ;;;
  14. ;;;   AUTODESKñ╜Ñq┤ú¿╤ª╣╡{ªí╢╚¿╤º@íu├■ªⁿív¬║░╤ª╥, ª╙ÑBñú▒╞░úª│Ñ⌠ª≤┐∙╗~¬║
  15. ;;;   Ñi»αíCAUTODESKñ╜Ñq»Sª╣º_╗{Ñ⌠ª≤»S⌐wÑ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºt
  16. ;;;   ÑX¿π¬║½O├╥íCAUTODESKñ╜ÑqªP«╔ÑτñúÑX¿πª╣╡{ªí░⌡ªµ«╔ñ@⌐wñú╖|íuññ┬_ív⌐╬
  17. ;;;   íuº╣Ñ■╡L╗~ív¬║½O├╥íC
  18. ;;;
  19. ;;; --------------------------------------------------------------------------;
  20. ;;; DESCRIPTION
  21. ;;;
  22. ;;;   This program allows you to redefine a Block and update the
  23. ;;;   Attributes associated with any previous insertions of that Block.
  24. ;;;   All new Attributes are added to the old Blocks and given their
  25. ;;;   default values. All old Attributes with equal tag values to the new
  26. ;;;   Attributes are redefined but retain their old value. And all old
  27. ;;;   Attributes not included in the new Block are deleted.
  28. ;;;
  29. ;;;   Note that if handles are enabled, new handles will be assigned to
  30. ;;;   each redefined block.
  31. ;;;
  32. ;;; --------------------------------------------------------------------------;
  33.  
  34. ;;;
  35. ;;; Oldatts sets "old_al" (OLD_Attribute_List) to the list of old Attributes
  36. ;;; for each Block.  The list does not include constant Attributes.
  37. ;;;
  38. (defun oldatts (/ e_name e_list cont)
  39.   (setq oa_ctr 0
  40.         cont   T
  41.         e_name b1
  42.   )
  43.   (while cont
  44.     (if (setq e_name (entnext e_name))
  45.       (progn
  46.         (setq e_list (entget e_name))
  47.         (if (and (= (cdr (assoc 0 e_list)) "ATTRIB")
  48.                  ;; NOT a constant attribute -- (cdr (assoc 70 e_list)) != 2)
  49.                  (/= (logand (cdr (assoc 70 e_list)) 2) 2))
  50.           (progn
  51.             (if old_al
  52.               (setq old_al (cons e_list old_al))
  53.               (setq old_al (list e_list))
  54.             )
  55.             (setq oa_ctr (1+ oa_ctr))           ; count the number of old atts
  56.           )
  57.           ;; else, exit
  58.           (setq cont nil)
  59.         )
  60.       )
  61.       (setq cont nil)
  62.     )
  63.   )
  64. )
  65. ;;;
  66. ;;; Newatts sets "new_al" to the list of new Attributes in the new Block.
  67. ;;; The list does not include constant Attributes.
  68. ;;;
  69. (defun newatts (ssetn ssl / i e_name e_list)
  70.   (setq i 0 na_ctr 0)
  71.   (while (< i ssl)
  72.     (if (setq e_name (ssname ssetn i))
  73.       (progn
  74.         (setq e_list (entget e_name))
  75.         (if (and (= (cdr (assoc 0 e_list)) "ATTDEF")
  76.                  ;; NOT a constant attribute -- (cdr (assoc 70 e_list)) != 2)
  77.                  (/= (logand (cdr (assoc 70 e_list)) 2) 2))
  78.           (progn
  79.             (if new_al
  80.               (setq new_al (cons e_list new_al))
  81.               (setq new_al (list e_list))
  82.             )
  83.             (setq na_ctr (1+ na_ctr))     ; count the number of new atts
  84.           )
  85.         )
  86.       )
  87.     )
  88.     (setq i (1+ i))
  89.   )
  90.   na_ctr
  91. )
  92. ;;;
  93. ;;; Compare the list of "old" to the list of "new" Attributes and make
  94. ;;; the two lists "same" and "preset". "Same" contains the old values of
  95. ;;; all the Attributes in "old" with equal tag values to some Attribute
  96. ;;; in "new" and the default values of all the other Attributes. "Preset"
  97. ;;; contains the preset Attributes in old with equal tag values to some
  98. ;;; Attribute in new.
  99. ;;;
  100. (defun compare (/ i j)
  101.   (setq i 0
  102.         j 0
  103.         pa_ctr 0
  104.         same nil
  105.         va_ctr 0
  106.         preset nil)
  107.   ;; "i" is a counter that increments until the number of new attributes
  108.   ;; is reached.
  109.   (while (< i na_ctr)
  110.     (cond
  111.       ;; If there are old attributes AND the tag strings of the old and new
  112.       ;; attributes are the same...
  113.       ((and old_al
  114.             (= (cdr (assoc 2 (nth j old_al))) (cdr (assoc 2 (nth i new_al)))))
  115.         ;; IS a preset attribute -- (cdr (assoc 70 e_list)) == 8)
  116.         (if (= (logand (cdr (assoc 70 (nth i new_al))) 8) 8)
  117.           ;; If the attribute is a preset attribute then add it to the list
  118.           ;; of preset attributes and increment the counter "pa_ctr".
  119.           ;; IS a preset attribute -- (cdr (assoc 70 e_list)) == 8)
  120.           (progn
  121.             (if preset
  122.               (setq preset (cons (nth j old_al) preset))
  123.               (setq preset (list (nth j old_al)))
  124.             )
  125.             (setq pa_ctr (1+ pa_ctr))     ; count preset atts
  126.           )
  127.           ;; Else, add it to the list of same attributes "same".
  128.           (if same
  129.             (setq same (cons (cdr (assoc 1 (nth j old_al))) same))
  130.             (setq same (list (cdr (assoc 1 (nth j old_al)))))
  131.           )
  132.         )
  133.         ;; If the attribute must be verified, increment counter "va_ctr".
  134.         ;; NOT a preset attribute -- (cdr (assoc 70 e_list)) != 8)
  135.         (if (and (/= (logand (cdr (assoc 70 (nth i new_al))) 8) 8)
  136.                  ;; IS a verified attribute -- (cdr (assoc 70 e_list)) == 4)
  137.                  (= (logand (cdr (assoc 70 (nth i new_al))) 4) 4))
  138.           (setq va_ctr (+ 1 va_ctr))
  139.         )
  140.         (setq i (1+ i))
  141.         (setq j 0)
  142.       )
  143.       ;; If the number of old attributes equals the old attribute counter "j"
  144.       ((= j oa_ctr)
  145.         ;; If this attribute is not a preset attribute, but is not in the
  146.         ;; old list, then add it to the list "same".
  147.         ;; NOT a preset attribute -- (cdr (assoc 70 e_list)) != 8)
  148.         (if (/= (logand (cdr (assoc 70 (nth i new_al))) 8) 8)
  149.           (if same
  150.             (setq same (cons (cdr (assoc 1 (nth i new_al))) same))
  151.             (setq same (list (cdr (assoc 1 (nth i new_al)))))
  152.           )
  153.         )
  154.         ;; NOT a preset attribute -- (cdr (assoc 70 e_list)) != 8)
  155.         (if (and (/= (logand (cdr (assoc 70 (nth i new_al))) 8) 8)
  156.                  ;; IS a verified attribute -- (cdr (assoc 70 e_list)) == 4)
  157.                  (= (logand (cdr (assoc 70 (nth i new_al))) 4) 4))
  158.           (setq va_ctr (+ 1 va_ctr))
  159.         )
  160.         (setq i (1+ i))
  161.         (setq j 0)
  162.       )
  163.       ;; Increment the old attribute counter "j"...
  164.       (t
  165.         (setq j (1+ j))
  166.       )
  167.     )
  168.   )
  169. )
  170. ;;;
  171. ;;; Find the entity for each of the "preset" Attributes in the newly
  172. ;;; inserted Block.
  173. ;;;
  174. (defun findpt ()
  175.   (setq test T)
  176.   (setq en (entnext e1))
  177.   (setq e_list (entget en))
  178.   (while test
  179.     (if (and (= (cdr (assoc 0 e_list)) "ATTRIB") (= (cdr (assoc 2 e_list)) tag))
  180.       (setq test nil)
  181.       (progn
  182.         (setq ex en)
  183.         (setq en (entnext ex))
  184.         (if e_list
  185.           (setq e_list (entget en))
  186.         )
  187.       )
  188.     )
  189.   )
  190. )
  191. ;;;
  192. ;;; Insert a new Block on top of each old Block and set its new Attributes
  193. ;;; to their values in the list "same". Then replace each of the "preset"
  194. ;;; Attributes with its old value.
  195. ;;;
  196. (defun redef (/ xsf ysf zsf ls i e1 v)
  197.   (command "_.UCS" "_E" b1)         ; define the block's UCS
  198.   (setq xsf (cdr (assoc 41 (entget b1)))) ; find x scale factor
  199.   (setq ysf (cdr (assoc 42 (entget b1)))) ; find y scale factor
  200.   (setq zsf (cdr (assoc 43 (entget b1)))) ; find z scale factor
  201.   (setq ls (length same))
  202.   (setq i 0)
  203.   (command "_.INSERT" bn "0.0,0.0,0.0" "_XYZ" xsf ysf zsf "0.0")
  204.   (while (< i ls)                     ; set attributes to their values
  205.     (command (nth i same))
  206.     (setq i (1+ i))
  207.   )
  208.   (while (< 0 va_ctr)
  209.     (command "")                      ; at prompts, verify attributes
  210.     (setq va_ctr (1- va_ctr))
  211.   )
  212.   (setq i 0)
  213.   (setq e1 (entlast))
  214.   (while (< 0 pa_ctr)                    ; edit each of the "preset" attributes
  215.     (setq tag (cdr (assoc 2 (nth i preset))))
  216.     (setq v (cdr (assoc 1 (nth i preset))))
  217.     (findpt)                          ; find the entity to modify
  218.     (setq e_list (subst (cons 1 v) (assoc 1 e_list) e_list))
  219.     (entmod e_list)                        ; modify the entity's value
  220.     (setq i (1+ i))
  221.     (setq pa_ctr (1- pa_ctr))
  222.   )
  223.   (command "_.UCS" "_P")                 ; restore the previous UCS
  224. )
  225. ;;;
  226. ;;; System variable save
  227. ;;;
  228. (defun modes (a)
  229.   (setq mlst '())
  230.   (repeat (length a)
  231.     (setq mlst (append mlst (list (list (car a) (getvar (car a))))))
  232.     (setq a (cdr a)))
  233. )
  234. ;;;
  235. ;;; System variable restore
  236. ;;;
  237. (defun moder ()
  238.   (repeat (length mlst)
  239.     (setvar (caar mlst) (cadar mlst))
  240.     (setq mlst (cdr mlst))
  241.   )
  242. )
  243. ;;;
  244. ;;; Internal error handler
  245. ;;;
  246. (defun attrerr (s)                    ; If an error (such as CTRL-C) occurs
  247.                                       ; while this command is active...
  248.   (if (/= s "Function cancelled")
  249.     (princ (strcat "\n┐∙╗~: " s))
  250.   )
  251.   (moder)                             ; restore saved modes
  252.   (setq *error* olderr)               ; restore old *error* handler
  253.   (princ)
  254. )
  255. ;;;
  256. ;;; Main program
  257. ;;;
  258. (defun C:ATTREDEF (/ k n olderr bn sseto ssetn pt ssl new_al
  259.                      old_al same preset b1 oa_ctr va_ctr na_ctr
  260.                   )
  261.   (setq k 0
  262.       n 0
  263.       test T
  264.       olderr *error*
  265.       *error* attrerr
  266.   )
  267.  
  268.   (modes '("CMDECHO" "ATTDIA" "ATTREQ" "GRIDMODE" "UCSFOLLOW"))
  269.   (setvar "cmdecho" 0)                ; turn cmdecho off
  270.   (setvar "attdia" 0)                 ; turn attdia off
  271.   (setvar "attreq" 1)                 ; turn attreq on
  272.   (setvar "gridmode" 0)               ; turn gridmode off
  273.   (setvar "ucsfollow" 0)              ; turn ucsfollow off
  274.  
  275.   (while
  276.     (progn
  277.       (setq bn (strcase (getstring
  278.         "\n╣w│╞¡½╖s⌐w╕qñºíu╣╧╕sívªW║┘: ")))
  279.       (if (tblsearch "block" bn)
  280.         (progn
  281.           (setq sseto (ssget "x" (list (cons 2 bn))))
  282.           (setq test nil)
  283.         )
  284.         (progn
  285.           (princ "\n╣╧╕síu")
  286.           (princ bn)
  287.           (princ "ívÑ╝⌐w╕q; ╜╨ªA╕╒íC\n")
  288.         )
  289.        )
  290.     )
  291.   )
  292.   (if sseto
  293.     (progn
  294.       (while
  295.         (progn
  296.           (princ "\n┐∩╛▄▓╒ª¿╖s╣╧╕s¬║íu╣╧ñ╕ív... ")
  297.           (if (null (setq ssetn (ssget)))
  298.             (princ "\nÑ╝┐∩¿∞╖s╣╧╕s; ╜╨ªA╕╒íC")
  299.             (setq test nil)
  300.           )
  301.         )
  302.       )
  303.       ;; find the list of new attributes
  304.       (setq na_ctr (newatts ssetn (sslength ssetn)) )
  305.       (if (> na_ctr 0)
  306.         (progn
  307.           (initget 1)
  308.           (setq pt (getpoint "\n╖s╣╧╕síu┤íñ▐┬Iív: "))
  309.           (setq ssl (sslength sseto))
  310.           ;; redefine the block
  311.           (command "_.BLOCK" bn "_Y" pt ssetn "")
  312.           (while (< k ssl)
  313.             (setq b1 (ssname sseto k))    ; For each old block...
  314.             (setq old_al nil)
  315.             (oldatts)                     ; find the list of old attributes,
  316.             (compare)                     ; compare the old list with the new,
  317.             (redef)                       ; and redefine its attributes.
  318.             (entdel b1)                   ; delete the old block.
  319.             (setq k (1+ k))
  320.           )
  321.           (command "_.REGENALL")
  322.         )
  323.         (princ "\n╖s╣╧╕sÑ╝¬■¿πíu─▌⌐╩ívíC")
  324.       )
  325.     )
  326.     (princ (strcat "\nºΣñú¿∞┤íñ▐íu╣╧╕s " bn "ív¿╤¡½╖s⌐w╕qíC"))
  327.   )
  328.   (moder)                             ; restore saved modes
  329.   (setq *error* olderr)               ; restore old *error* handler
  330.   (princ)
  331. )
  332.  
  333. (defun c:at () (c:attredef))
  334. (princ
  335.   "\n\tíuC:ATtredefívñw╕ⁿñJ; ╜╨ÑH AT ⌐╬ ATTREDEF ▒╥░╩½ⁿÑOíC")
  336. (princ)
  337.