;;-------------------=={ Attribute Colour }==-----------------;;
;;                                                            ;;
;;  Prompts for a selection of attributed blocks and displays ;;
;;  a dialog interface enabling the user to change the colour ;;
;;  of specific attribute tags.                               ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Version 1.0    -    24-02-2011                            ;;
;;                                                            ;;
;;  First Release.                                            ;;
;;------------------------------------------------------------;;

(defun c:lm_AttCol ( / old_cmd _dclsel lst s ss )

  (or *attcolour* (setq *attcolour* 3)) ;; First time default colour
  (defun _dclsel ( lst / file tmp dch return )
    (setq tmp
      (mai_make_dcl
        (list "attcol : dialog { label = \"µ÷Õû¿éÊôÐÔÑÕÉ«\"; spacer;"
                "  : list_box { label = \"Ñ¡Ôñ±êÇ©\"; key = \"tags\"; fixed_width = false; multiple_select = true ; alignment = centered; }"
                "  : boxed_column { label = \"ÑÕÉ«\";"
                "    : row { spacer;"
                "      : button { key = \"but\"; width = 12; fixed_width = true; label = \"Ñ¡ÔñÑÕÉ«\"; }"
                "      : image_button { key = \"img\"; alignment = centered; height = 1.5; width = 4.0;"
                "                       fixed_width = true; fixed_height = true; color = 2; }"
                "      spacer;}spacer;}spacer; ok_cancel;}"
        )
      )
      dch (load_dialog tmp)
    )
    (new_dialog "attcol" dch)
    (mai_filldcl_list "tags" lst)
    (setq return (set_tile "tags" "0"))
    (mai_filldcl_image "img" *attcolour* nil)
    (action_tile "img" "(mai_filldcl_image\"img\"(setq *attcolour*(cond((acad_colordlg *attcolour*))(*attcolour*)))nil)")
    (action_tile "but" "(mai_filldcl_image\"img\"(setq *attcolour*(cond((acad_colordlg *attcolour*))(*attcolour*)))nil)")
    (action_tile "tags" "(setq return $value)")
    (setq return
          (if (= 1 (start_dialog))
              (mapcar '(lambda(x)(nth x lst))(read (strcat "(" return ")")))
          )
    )
    (unload_dialog dch)
    (mai_dos_delete tmp)
    return
  )

  (mini_start nil)
  (setq ss (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object))))    
  (if
    (and 
      (princ "\nÑ¡ÔñÒªÐÞ¸ÄÑÕÉ«µÄ¿éÊôÐÔ:")
      (ssget "_:L" '((0 . "INSERT") (66 . 1)))
      (progn
        (vlax-for obj ss          
          (foreach att
            (append (vlax-invoke obj 'GetAttributes) (vlax-invoke obj 'GetConstantAttributes))
            (setq lst (cons (cons (vla-get-TagString att) att) lst))
          )
        )
        (vla-delete ss)
        (setq s (_dclsel (acad_strlsort (mai_remove_same (mapcar 'car lst)))))
      )
    )
    (foreach pair lst (if (vl-position (car pair) s) (vla-put-color (cdr pair) *attcolour*)))
  )
  (mai_end)
)
