Trying to get BACKCOLOR from colored Graphic Button

Started by RGUS, February 10, 2013, 09:32:12 PM

Previous topic - Next topic

RGUS

Ok... so I don't like the tweeness of the ACI Color Dialog that comes with standard AutoCAD
So thinking... hey OpenDCL could do this...
I know, I know... probably not the best implementation of this really cool product... but hey...

So anyway... attached are the odcl and lsp files for it... and all I want to do is return the correct number for the background color for each graphic button... but do you think I understand how... nope.

Can someone... please point me in the right direction... I'm stumped right now.

Thanks
Deane


owenwengerd

Is this what you're looking for?

Code (autolisp) Select
(defun c:kolor_OnClicked (/)
(dcl_Form_Close "color_swatch" "color_swatch" (dcl_Control_GetBackColor kolor))
)
Owen Wengerd (Outside The Box) / ManuSoft

RGUS

Ummm... it's a good call to certainly close the dialog box after picking... but if I pick... say color 58 ... it always returns 18 as the "GetBackColor" number... I can't set the current color to that selected.

roy_043

The problem is that you are using the same VarName "kolor" for all Graphic Buttons. Ultimately the variable kolor will point to one control only: the last control with that VarName in the ZOrder. In the current ODCL this is the COLOR18 Graphic Button.

I can think of two solutions:
1. Create a unique OnClicked function for each color button.
2. Use a single Picture Box for all color swatches.

I have an example of the last solution. I will try to upload it today. I'll have to look it over first. ;)


RGUS

Quote from: roy_043 on February 11, 2013, 04:03:36 AM
Quote from: roy_043 on February 11, 2013, 01:19:43 AM
I have an example of the last solution.
Link: http://www.opendcl.com/forum/index.php?topic=1946.0

Wowzer... Man, that's some coding!
Thanks for the example and idea. I considered making a variable for each graphic button... but the lisp file would be enormous.

I tried your example function with the example provided in the code:
(FlexColorDialog '((1 2 3 4 5 6 7 8 9) (250 251 252 253 254 255 nil 0 256) ((11 186 247) (247 186 11))) nil T)

However AutoCAD 2013 spat this error back at me... I'll have to read your lines carefully I guess to get this to work.
Thanks a lot for your help

roy_043

I will look into the error. Since the error seems to be related to colors-as-RGB-lists it think this will probably work:
Code (autolisp) Select
(FlexColorDialog '((1 2 3 4 5 6 7 8 9) (250 251 252 253 254 255 nil 0 256) (11 12)) nil T)

Quote from: RGUS on February 11, 2013, 05:18:00 AM
but the lisp file would be enormous.
Not necessarily. You can create Lisp functions programmatically:
Code (autolisp) Select
(setq indexList '(1 2 3 4))

(foreach index indexList
  (eval
    (read
      (strcat
        "(defun c:Color_Swatch_Color" (itoa index) " () (ColorButtonOnClick " (itoa index) "))"
      )
    )
  )
)

(defun ColorButtonOnClick (index)
  (command "color" index)
  (dcl_Form_Close "Color_Swatch" "Color_Swatch")
)



RGUS

Thanks roy...

That self generating function code stuff worked a treat.
Probably not the most efficient way to do it but it works... and that's all it needs to do.

Thanks for updating for code for the other routine... a little more learning and I just may rethink the way I'm doing it.

Thanks again for your help. 

RGUS

Ok... so using "roy_043" help with creating functions, I've change the code to work... and it does.
Primarily, I wanted a bigger color swatch than what comes standard with AutoCAD... because I'm old and blind.

Getting it to work may help others see how it's done and provide ideas for other routines.

owenwengerd

Looks good. This, or some variation on it, would make a nice OpenDCL sample. If you don't mind, I my steal your idea and make a sample out of it.
Owen Wengerd (Outside The Box) / ManuSoft

RGUS

No problems Owen... would love to see the sample when you're done with it though.
Thanks for a great way to make DCL so much better than AutoDESK ever dreamed of!

roy_043

@RGUS: To make it extra nice: ;)
- Make the ByLayer button functional.
- Add a ByBlock button.
- End the main function with a (princ) statement.

RGUS

Something like this'roy'?
Though trying to suppress the '0' when exiting the dialog box is beyond my understanding.
I thought about adding the line
(strcat "Entity Color Set to: " (itoa index))

but that damn 0 kept popping up.

Added the bits you mentioned... attached

roy_043

This is what I mean:
Code (autolisp) Select
(defun c:CSW()
  (dcl_LoadProject "color_swatch")
  (dcl_Form_Show "color_swatch" "color_swatch")
  (princ) ; (princ) statement to suppress any return value.
)