2008-08-27 05:17 UTC
For anyone following along ....
... there are a couple of things to remember if trying to set the current selection to a cpecific Color Number ... the color MUST be in the Combo Display List
... hope this helps ...
for example .. set the current layer to have a color higher than 7 ... and type DOIT at the command line to see that the combo list will be populated with the Layer Color ..
NOTE: the attached ODCL is compiled with Studio Build 5.0.0.23
... there are a couple of things to remember if trying to set the current selection to a cpecific Color Number ... the color MUST be in the Combo Display List
... hope this helps ...
for example .. set the current layer to have a color higher than 7 ... and type DOIT at the command line to see that the combo list will be populated with the Layer Color ..
NOTE: the attached ODCL is compiled with Studio Build 5.0.0.23
(defun c:doit () (TestColorCombo))
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(defun TestColorCombo (/
_ConvertColorStringToNumber _ResetComboBox
;;
currentLayerColorNumber
)
(setq currentLayerColorNumber
(vla-get-Color (vla-get-activelayer
(vla-get-activedocument
(vlax-get-acad-object)
)
)
)
)
;;-----------------------------------------------------------
;;
;; Convert the return value from the dcl_ComboBox_GetTBText Method to a Color Number (0-256)
;; (_ConvertColorStringToNumber "12")
;; (_ConvertColorStringToNumber "Color 122")
;; (_ConvertColorStringToNumber "Cyan") (_ConvertColorStringToNumber "0")
;;
(defun _ConvertColorStringToNumber (ColorString / tmp)
(cond
((numberp
(setq tmp (read (vl-string-subst "" "Color " ColorString)))
)
tmp
)
((numberp (setq
tmp (eval
(read
(strcat "ac"
(vl-string-subst "" "Color " ColorString)
)
)
)
)
)
tmp
)
(t 256)
)
)
;;-----------------------------------------------------------
;;
(defun _ResetComboBox (ColorNumber / stringValue listIndex)
(cond ((Setq listIndex (dcl_ComboBox_FindColor
TestColorCombo_Main_ComboBox1
ColorNumber
)
)
;; the color exists in the display list, so select it by it's index
(dcl_ComboBox_SetCurSel TestColorCombo_Main_ComboBox1
listIndex
)
)
;;
;; the color is not in the combo display,
;; so add it if it's a valid color number.
((and (>= ColorNumber 8) (<= ColorNumber 256))
(dcl_ComboBox_AddColor TestColorCombo_Main_ComboBox1
ColorNumber
)
(dcl_ComboBox_SetCurSel
TestColorCombo_Main_ComboBox1
(dcl_ComboBox_FindColor TestColorCombo_Main_ComboBox1
ColorNumber
)
)
)
;;
)
(Setq stringValue
(dcl_ComboBox_GetTBText TestColorCombo_Main_ComboBox1
)
)
(c:TestColorCombo_Main_ComboBox1_OnSelChanged 0 stringValue)
)
;;-----------------------------------------------------------
;;
;; Main Entry Point
;;-----------------------------------------------------------
;;---------------(findFile "TestColorCombo.odcl")
(dcl_project_load "TestColorCombo.odcl" T)
(dcl_form_show TestColorCombo_main)
;;
(princ)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(defun c:TestColorCombo_Main_OnInitialize (/)
(_ResetComboBox currentLayerColorNumber)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(defun c:TestColorCombo_Main_TextBox3_OnReturnPressed (/)
(c:TestColorCombo_Main_DoIt_OnClicked)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(defun c:TestColorCombo_Main_ComboBox1_OnSelChanged
(nSelection sSelText /)
(dcl_Control_SetText TestColorCombo_Main_TextBox1
(itoa (_ConvertColorStringToNumber sSelText))
)
(dcl_Control_SetText TestColorCombo_Main_TextBox2 sSelText)
(dcl_Control_SetText TestColorCombo_Main_TextBox3 "")
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(defun c:TestColorCombo_Main_DoIt_OnClicked
(/ TextValue ColorNumber tmp)
(Setq TextValue (dcl_Control_GetText TestColorCombo_Main_TextBox3)
ColorNumber (if (numberp (setq tmp (read TextValue)))
tmp
256
)
ColorNumber (if (and (>= ColorNumber 0) (<= ColorNumber 256))
ColorNumber
256
)
)
(_ResetComboBox ColorNumber)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(princ)
