Author Topic: Sharing some findings - True Color (RGB) to AC Index - after awful experience...  (Read 394 times)

0 Members and 1 Guest are viewing this topic.

Rustabout

  • Newt
  • Posts: 83
I'm making a routine which I might post later. I had a horrible time trying to get RGB true color values converted to index colors using the vla-setRGB function. I think I almost started crying at one point but finally got it...

It appears that my VARIABLE NAMES needed to be all lower-lower case (and possible not have any special characters in them).

Something really strange was happening in that if I plugged in actual numbers (and not variables) the routine would work. As soon as I tried the exact same thing with variables the routine would crash. Not only that it would actually clear my variable from memory (set it to 'nil'), but not update my watch window.

I got smart and downloaded Lee Mac's routine. Same problem. As soon as I switched to lower-case variable names without any special characters, everything started working perfectly. I've never experienced this with AutoLISP before. So thought I would share my findings. I will post my code once it's done if anyone is interested in what I'm actually creating.

Synopsis: Strange behavior using VLA-SETRGB function - appears that variable names used for arguments might have to be LOWER CASE ONLY (and may or may not work with 'special' characters).

d2010

  • Bull Frog
  • Posts: 201
Even your have great succesfull, then you got convert all images to 256color-s bitmap.
You can draw image directly inside Drawing.dwg
I inject the Great History of U.S.dwg inside GstarCad.exe
Great Love of Old-Times :idea:
« Last Edit: September 05, 2021, 08:14:49 AM by d2010 »

VovKa

  • Swamp Rat
  • Posts: 1369
  • Ukraine
It appears that my VARIABLE NAMES needed to be all lower-lower case (and possible not have any special characters in them).
hmmm
strange
variable names are symbols, they don't have a 'case'
we need to see your code, it may be a bug of your particular acad installation

Rustabout

  • Newt
  • Posts: 83
d2010: I notice you were using GstarCAD. How did you find it? As far as the 256 color limit goes, I'm trying to do something relatively simple so image quality won't be a concern.

Vovka: I agree, and it seems like I might be missing something here. I'll run some trials and try to find out wtf was going on. Thereafter I'll post some code. It could have something to do with my ACAD. The strangest thing I was finding was that the variables I would set and declare would be reset to 'nil'. I had some trouble in the past with true colors and simply took a different approach opposed to figuring out what actually went wrong. I'm keen on getting to the bottom of this.

Rustabout

  • Newt
  • Posts: 83
Well... after trying out every possible combination I cannot reproduce what was happening. I did restart AutoCAD since my last session. I was also building code with dialog boxes and might have thrown something unintentionally. I might delete this post actually unless I can reproduce the error.

ronjonp

  • Needs a day job
  • Posts: 7327
Even your have great succesfull, then you got convert all images to 256color-s bitmap.
You can draw image directly inside Drawing.dwg
I inject the Great History of U.S.dwg inside GstarCad.exe
Great Love of Old-Times :idea:
That looks like AutoCAD r14 .. which IMO was a great release.

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Rustabout

  • Newt
  • Posts: 83
I'm going to post what I'm working on just in case it's of any use or at least eases some curiosity as to what I'm going (I did get it to work). I'm just making a system to quickly override colors. I needed to have an approximate preview of the color (the index color will be close enough in this case). This isn't done yet and I DON'T need any help; comments and suggestions are welcome of course. I basically just have to finish the rest of the code which is the easy part. In fact I have the code it's just not on this computer.

My LISP Code (remember it's not done yet):

Code: [Select]

(defun C:ColorOverride ( / )

  (setq dcl_fileReference (load_dialog "C:\\AutoCAD Local Files\\LISP\\# - WIP - COLOR OVERRIDE (DCL).dcl"))

  (setq dcl_dialogReference (new_dialog "Color_Override_Dialog" dcl_fileReference))

  ; - VARIABLE HANDLING - ;

  (setq flag nil)

  (if (= redvalue nil) (setq redvalue 255)) (if (= greenvalue nil) (setq greenvalue 125)) (if (= bluevalue nil) (setq bluevalue 125))

    (setq trueColorObject (vla-get-trueColor (vla-item (vla-get-layers (vla-get-activeDocument (vlax-get-acad-object))) "0")))

    (vla-setrgb trueColorObject redvalue greenvalue bluevalue)

    (setq imageIndexColor (vla-get-colorIndex trueColorObject))

  ; - END VARIABLE HANDLING - ;


  (start_image "colorPreviewer")

  (fill_image 0 0 (dimx_tile "colorPreviewer") (dimy_tile "colorPreviewer") imageIndexColor)

  (end_image)
 

  (set_tile "red" (itoa redvalue))

  (set_tile "green" (itoa greenvalue))

  (set_tile "blue" (itoa bluevalue))
 

  (action_tile "red" "(clr-Override_sliderAction)")

  (action_tile "green" "(clr-Override_sliderAction)")

  (action_tile "blue" "(clr-Override_sliderAction)")
 

  (action_tile "accept" "(done_dialog) (setq flag T)")

  (action_tile "cancel" "(done_dialog) (setq flag nil)")
 

  (start_dialog)

  (unload_dialog dcl_fileReference)


  (if (= flag T) (alert (strcat "Current color index = " (itoa redvalue) ", " (itoa greenvalue) ", " (itoa bluevalue) ".")))

  (if (= flag nil) (print "Function Cancelled Successfully."))

  ) ; end main defun


  (defun clr-Override_sliderAction  ( / )

    (print "check1")

    (setq redvalue (atoi (get_tile "red")))

    (setq greenvalue (atoi (get_tile "green")))

    (setq bluevalue (atoi (get_tile "blue")))

    (print "check1")

    (setq trueColorObject (vla-get-trueColor (vla-item (vla-get-layers (vla-get-activeDocument (vlax-get-acad-object))) "0")))

    (vla-setrgb trueColorObject redvalue greenvalue bluevalue)

    (setq imageIndexColor (vla-get-colorIndex trueColorObject))

    (start_image "colorPreviewer")

    (fill_image 0 0 (dimx_tile "colorPreviewer") (dimy_tile "colorPreviewer") imageIndexColor)

    (end_image)

   ) ; end defun clr-Override_sliderAction


Rustabout

  • Newt
  • Posts: 83
And the DCL:

Code: [Select]

Color_Override_Dialog : dialog { label = "Tag Settings" ;

    : column { children_alignment = centered ;

           : spacer { height = 1 ; }

        : image {
                  key = "colorPreviewer" ;
                  height = 5.0 ;
                  width = 10.0 ;
                  fixed_width = true;
                  fixed_height = true;
                }

         : spacer { height = 1 ; }

         : row { children_alignment = centered ;

                 : text_part {
                               label = "Red" ;
                             }

                 : slider {
                            key = "red" ;
                            max_value = 255 ;
                            min_value = 0 ;
                            small_increment = 1 ;
                            big_increment = 5 ;
                            allow_accept = false ;
                          }

                }

                 : spacer { height = 1 ; }

         : row { children_alignment = centered ;

                 : text_part {
                               label = "Green" ;
                             }

                 : slider {
                            key = "green" ;
                            max_value = 255 ;
                            min_value = 0 ;
                            small_increment = 1 ;
                            big_increment = 5 ;
                            allow_accept = false ;
                          }

                }

           : spacer { height = 1 ; }

         : row { children_alignment = centered ;

                 : text_part {
                               label = "Blue" ;
                             }

                 : slider {
                            key = "blue" ;
                            max_value = 255 ;
                            min_value = 0 ;
                            small_increment = 1 ;
                            big_increment = 5 ;
                            allow_accept = false ;
                          }

                }

           : spacer { height = 1 ; }

                       ok_cancel ;

      } // end main column wrap

    } //end dialog


BIGAL

  • Swamp Rat
  • Posts: 829
  • 30 + years of using Autocad
Are you aware of (acad_colordlg x) where x is a color number and the rgb version. (acad_truecolordlg '(62 . 215)) returns rgb number.
A man who never made a mistake never made anything

Rustabout

  • Newt
  • Posts: 83
BIGAL: Thank you very much! This might just be the solution I need for another program I'm working on. I searched high and low for these functions with no success.