;;;从AutoCAD 2013 Active Reference帮助中code Examples中提取
;;;本源代码由 xshrimp 2013.2.20 搜集整理,版权归原作者所有!


(vl-load-com)
(defun c:Example_SetColor()
    ;; This example creates a TableStyle object and sets values for 
    ;; the style name and other attributes.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
    (setq dictionaries (vla-get-Dictionaries doc))
    (setq dictObj (vla-Item dictionaries "acad_tablestyle"))
    
    ;; Get the current TableStyle object
    (setq tableStyle (vla-Item dictObj (vla-GetVariable doc "CTABLESTYLE")))
      
    (setq colCurrent (vla-GetBackgroundColor tableStyle (+ acDataRow acTitleRow)))
    (setq colRowCurrent (vla-GetColor tableStyle acDataRow))
    (setq colNoneCurrent (vla-GetBackgroundColorNone tableStyle acHeaderRow))

    (alert (strcat "Table colors \n"
		   "Background ACI value = " (itoa (vla-get-ColorIndex colCurrent)) "\n"
		   "Row Text ACI value = " (itoa (vla-get-ColorIndex colRowCurrent)) "\n"
		   "Background None = " (if (= colNoneCurrent :vlax-true) "True" "False")))
  
    (setq col (vlax-create-object "AutoCAD.AcCmColor.19"))
    (vla-SetRGB col 0 0 255)
    (vla-SetBackgroundColor tableStyle acTitleRow col)
    (vla-SetRGB col 255 0 0)
    (vla-SetColor tableStyle acDataRow col)
    (vla-SetBackgroundColorNone tableStyle acHeaderRow (if (= colNoneCurrent :vlax-true) :vlax-false :vlax-true))
  
    (setq colNew (vla-GetBackgroundColor tableStyle acTitleRow))
    (setq colRowNew (vla-GetColor tableStyle acDataRow))
    (setq colNoneNew (vla-GetBackgroundColorNone tableStyle acHeaderRow))
    (alert (strcat "Table colors \n"
		   "Background ACI value = " (itoa (vla-get-ColorIndex colNew)) "\n"
		   "Row Text ACI value = " (itoa (vla-get-ColorIndex colRowNew)) "\n"
		   "Background None = " (if (= colNoneNew :vlax-true) "True" "False")))

    (vla-SetBackgroundColor tableStyle acTitleRow colCurrent)
    (vla-SetColor tableStyle acDataRow colRowCurrent)
    (vla-SetBackgroundColorNone tableStyle acHeaderRow colNoneCurrent)

    (alert "Reset the table style back to its original values.")

    (vlax-release-object col)
)