OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: RGUS on February 10, 2013, 09:32:12 PM

Title: Trying to get BACKCOLOR from colored Graphic Button
Post by: RGUS 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

Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: owenwengerd 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))
)
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: RGUS 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.
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: roy_043 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. ;)
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: 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
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: RGUS on February 11, 2013, 05:18:00 AM
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
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: roy_043 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)

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")
)

Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: roy_043 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
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: RGUS 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. 
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: RGUS 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.
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: owenwengerd 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.
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: RGUS 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!
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: roy_043 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.
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: RGUS 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
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: roy_043 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.
)
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: RGUS on February 16, 2013, 05:36:53 PM
See I knew it would be simple... I just need another 40 years in this stuff to begin to see the wood from the trees.
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: hanslammerts on January 31, 2017, 01:24:29 PM
When try to use this, (AutoCAD 2017)

files Reply #13 with
command comment Reply #14 Roy..

this is what happens..

Figure this line is breaking the party
Command: ; error: AutoCAD command rejected: "color"
change it to (command "-color".. ) and that should work..? *EDIT * Not..

*EDIT*
Added opendcl directory for files as trusted directory in AutoCAD, restart, .. negative
I find it strange that in the odcl nothing is defined when i check 'event' 'onclick'(?), none of the numbers have (?)
Only esc at some point does give me a way out..
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: RGUS on January 31, 2017, 01:29:40 PM
Quote from: hanslammerts on January 31, 2017, 01:24:29 PM
When try to use this, (AutoCAD 2017)
this is what happens..

Just tried the code provided earlier with AutoCAD 2017 and it displays perfectly. I couldn't get the error you are having.
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: hanslammerts on January 31, 2017, 02:09:34 PM
I think this dialog is very good. I model / draw all with thé most simple layernames onw can think of ;-)..:
1,2,3,4,5 ..following colorcode.

Great stuff!
With some tweaks i would like it to turn into this this..

(..replacement for..)
command:1
command:2
command:3
etc.

(> if layers is not available, make layer > then layer current + start function to select object to make turn it this layer..)


Code (autolisp) Select

;;; either change current selection to current layer or start drawing line on current layer
(defun XYZ_laycmnd ( lyr / ss1 p1 idx)
  ;(c:makel)
  (if (and (tblsearch "LAYER" lyr)
           (setq ss1 (ssget "_I"))
      )
    ;; if selection, change to layer
    (repeat (setq idx (sslength ss1))
      (vla-put-layer
        (vlax-ename->vla-object (ssname ss1 (setq idx (1- idx))))
        lyr
      )
    )
    ;; if no selection, start drawing line on layer
    (progn
      (command "layer" "set" lyr "on" lyr "")
      (c:lac)
     
;;;      (if (setq p1 (getpoint "LINE From point: "))
;;;        (command "line" p1)
;;;      ) ;if
    ) ;progn
  ) ;if
)


Code (autolisp) Select

(defun c:1 (/ p1)  (XYZ_laycmnd "1") (princ))
(defun c:2 (/ p1)  (XYZ_laycmnd "2") (princ))
(defun c:3 (/ p1)   (XYZ_laycmnd "3") (princ))







Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: hanslammerts on February 01, 2017, 02:47:20 PM
Trying to get this routine started, but failing in more then one way..

- noticed that Autolisp file path was assigned to a local c:\ drive from the author. How to get rid of this? i don't how this can be set to <none>
- See that none of the index number have event  'clicked' assigned, shouldn't that be?
- BBlock was not there i believe.
- did some editing in the code. I have the feeling something in the code that is ;;;commented is failing and giving errors.

If someone can help me a little in the right direction, i would appriciate that.
The errors do not seem as normal behaviour for a beginner..
thanks
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: roy_043 on February 02, 2017, 06:14:57 AM
Fixed files attached.

Modifications to the .odcl file:
1.
Menu > Project > Set AutoLISP File Name > select .lsp file
I don't know how to remove this file name, but it is only used in the Studio.
See: Menu > Tools > Write Events to Lisp File
2.
Menu > Tools > Clear Lisp Symbol Names > OK
3.
Menu > Tools > Reset Event Names > OK

Note 1:
It is important that you do not call AutoCAD commands in event handlers.
Note 2:
The dialog is not finished. Only the buttons on top row and the last three buttons on the bottom row have an OnClicked event. So there is still some work to do.
Note 3:
Why don't you use the built-in color dialog?:
Code (autolisp) Select
(acad_colordlg 1 T)
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: hanslammerts on February 02, 2017, 02:23:15 PM
Nice of you to take a look Roy! :)

Sofar i made it to this. It's not quite finished yet and i bet you have some findings on my coding..

done this:
- buttons work
- make layer if not available
- functions "select layer" combined with "change elements" work (user can use escape, or tune it to use it only as colornumber..)

- a bottom part to expand , *EDIT*
- works, review the code if you like....  12-2-2017 *EDIT*  see animated gif
- needs better handling support : select objects first  17-2-2017 *EDIT*
- defun c:lac handles select objects first 17-2-2017 *EDIT*
- defun c:lac handles select objects first better 22-2-2017 *EDIT*

For now, i like it ..

Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: hanslammerts on February 07, 2017, 02:10:33 PM
I made the dialog a modeless one.
Somehow i can get the button down / expand turn the real unfolding good.. hmmm  :-\

it has height 45 / 450 
width 750

Code (autolisp) Select


(defun c:color_swatch/COLOR_SWATCH/cmdExpand#OnClicked ( / );_ expand
(if (< (Cadr (dcl-Form-GetControlArea color_swatch/COLOR_SWATCH)) 400)
(progn
(dcl-Form-Resize color_swatch/COLOR_SWATCH 750 450)
(dcl-Control-SetPicture color_swatch/COLOR_SWATCH/cmdExpand 100)
) ());_ if
   

(if (> (Cadr (dcl-Form-GetControlArea color_swatch/COLOR_SWATCH)) 400)
(progn
(dcl-Form-Resize color_swatch/COLOR_SWATCH 750 45)
(dcl-Control-SetPicture color_swatch/COLOR_SWATCH/cmdExpand 101)
) ());_if
)

(princ)



See last previous post for code..
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: roy_043 on February 08, 2017, 01:38:24 AM
Hans, in the example you refer to (c:FormMover/Form1/cmdExpand#OnClicked) there is only a single 'if', why are there two in your code?
BTW 1:
At least 25 buttons still do not have an OnClicked event.
BTW 2:
The dcl-Form-Show method behaves differently for a modeless from. So you will have to revise the current logic of the c:CSW function.
Title: Re: Trying to get BACKCOLOR from colored Graphic Button
Post by: hanslammerts on February 12, 2017, 02:13:47 PM
I updated the code. #21
Think its working a lot better now.
Thanks for your feedback Roy_043!