Test Color Combo Box

Started by Kerry, August 26, 2008, 10:17:41 PM

Previous topic - Next topic

Kerry

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


(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)
Perfection is not optional.
My other home is TheSwamp

jb

Nice example Kerry - thanks.

How's 5.0.0.23 doing?  I'm still using 4 - stability reasons.
James Buzbee
Managing Memeber
Black Horse Development, LLC

Kerry

Quote from: jb on August 29, 2008, 06:31:49 AM
Nice example Kerry - thanks.

How's 5.0.0.23 doing?  I'm still using 4 - stability reasons.

thanks.

5.0.0.23 seems fine James .. i'm using it for production code without problem.
Perfection is not optional.
My other home is TheSwamp

BazzaCAD

I think the only major changes Owen has left in 5.0 Alpha is ActiveX stuff.
(But I could be wrong)
a.k.a.
Barry Ralphs
barryDOTralphsATgmailDOTcom

owenwengerd

Quote from: BazzaCAD on August 29, 2008, 04:27:33 PM
I think the only major changes Owen has left in 5.0 Alpha is ActiveX stuff.
(But I could be wrong)

Yes, and I'm working on that now.  There are still some palette issues that I've been having trouble resolving, and I'd like to get the "selected control" painting in Studio more robust.  Everything else is pretty stable.
Owen Wengerd (Outside The Box) / ManuSoft

Fred Tomke

Hello,

I want to add my "mustard": We have distributed our new release using 5.0.0.19 as a stable release in our mind. All other new things changed after 5.0.0.19 are not as relevantly for us to publish an urgently servicepack.

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]