Jump to content

Get color funcion - clever than mine


Recommended Posts

Posted

Hi there, I've wrote a function to get and change color but I've the problem among versions of autocad. I use an English version of it but my brother has an Italian version...

(defun colore_da_lista ( value /)

    
   (COND ( (= (substr Value 1 6) "Colore")
         (setq colore_cordolo (substr Value 8)))
	 ( (= (substr Value 1 6) "Color ")
         (setq colore_cordolo (substr Value 7)))

     ( (OR(= Value "Rosso") (= Value "Red"))
         (setq colore_cordolo "1"))
         ( (OR(= value "Giallo") (= value "Yellow"))
         (setq colore_cordolo "2"))
         ( (OR(= value "Verde") (= value "Green"))
         (setq colore_cordolo "3"))
         ( (OR(= value "Ciano") (= value "Cyan"))
         (setq colore_cordolo "4"))
         ( (OR(= value "Blu") (= value "Blue"))
         (setq colore_cordolo "5"))
         ( (OR(= value "Magenta") (= value "Magenta"))
         (setq colore_cordolo "6"))
         ( (OR(= value "Bianco") (= value "White"))
         (setq colore_cordolo "7"))
         ( (OR(= value "DaLayer") (= value "ByLayer"))
         (setq colore_cordolo "152"))
         
         (t (princ colore_cordolo))
         )
   
)

There is a better way t accomplish that? I'm sure that who develops program didn't do that for every language :)

The value comes from a FORM in OPENDCL.

Thanks for your help!

Dennis

Posted

I think this code does not work as intended.

Maybe you should look at assoc lists?

Posted
1 hour ago, Roy_043 said:

I think this code does not work as intended.

Maybe you should look at assoc lists?

Hello! Thanks, I think you're right!

I didn't know that 256 is the number for "ByLayer" !! Thank you very much! I'll fix my code :)

(dcl-Control-GetItemData cordoli/cordoli/colore_cordolo) with that I get (256 0 1 2 3 4 5 6 7) !

Posted

Hi,

A hint for you to shorten the codes a bit if you would like to. :) 

(or (vl-some '(lambda (c) (if (or (= value (car c)) (= value (cadr c))) (setq r (caddr c))))
             '(("Rosso" "Red" "1")
               ("Giallo" "Yellow" "2")))
    (setq r 256)
    )

So the variable 'r' should be assigned with the desired return value.

Posted (edited)

@MastroLube

What I meant with my comment:

(colore_da_lista "Color White")    => "White"
(colore_da_lista "Color Red")      => "Red"
(colore_da_lista "Colore Blu")     => "Blu"
(colore_da_lista "Colore DaLayer") => "DaLayer"

So most of your cond structure never gets executed.

EDIT: I realise now that I have probably made a wrong assumption regarding the input.

Edited by Roy_043
Posted

One more thing is that, why do you have the return value of colour in a string type?

I forgot to change it to integer in my previous reply to you so please be a ware of that.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...