Author Topic: Trying to get BACKCOLOR from colored Graphic Button  (Read 10038 times)

RGUS

  • Member
  • *
  • Posts: 28
Trying to get BACKCOLOR from colored Graphic Button
« on: February 10, 2013, 09:32:12 PM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 3002
    • Outside The Box
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #1 on: February 10, 2013, 09:49:38 PM »
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))
)

RGUS

  • Member
  • *
  • Posts: 28
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #2 on: February 10, 2013, 10:22:26 PM »
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

  • Sr. Member
  • ****
  • Posts: 361
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #3 on: February 11, 2013, 01:19:43 AM »
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. ;)

roy_043

  • Sr. Member
  • ****
  • Posts: 361

RGUS

  • Member
  • *
  • Posts: 28
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #5 on: February 11, 2013, 05:18:00 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

  • Sr. Member
  • ****
  • Posts: 361
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #6 on: February 11, 2013, 05:51:13 AM »
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)
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")
)

roy_043

  • Sr. Member
  • ****
  • Posts: 361
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #7 on: February 11, 2013, 06:43:51 AM »
I have updated the Lisp file in my FlexColorDialog post:
http://www.opendcl.com/forum/index.php?topic=1946.0

RGUS

  • Member
  • *
  • Posts: 28
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #8 on: February 11, 2013, 08:27:14 PM »
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

  • Member
  • *
  • Posts: 28
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #9 on: February 15, 2013, 09:41:41 AM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 3002
    • Outside The Box
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #10 on: February 15, 2013, 10:07:46 AM »
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.

RGUS

  • Member
  • *
  • Posts: 28
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #11 on: February 15, 2013, 10:29:54 AM »
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

  • Sr. Member
  • ****
  • Posts: 361
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #12 on: February 15, 2013, 01:54:05 PM »
@RGUS: To make it extra nice: ;)
- Make the ByLayer button functional.
- Add a ByBlock button.
- End the main function with a (princ) statement.

RGUS

  • Member
  • *
  • Posts: 28
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #13 on: February 15, 2013, 04:11:33 PM »
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

  • Sr. Member
  • ****
  • Posts: 361
Re: Trying to get BACKCOLOR from colored Graphic Button
« Reply #14 on: February 16, 2013, 02:09:35 AM »
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.
)