MastroLube Posted August 31, 2018 Posted August 31, 2018 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 Quote
Roy_043 Posted August 31, 2018 Posted August 31, 2018 I think this code does not work as intended. Maybe you should look at assoc lists? Quote
MastroLube Posted August 31, 2018 Author Posted August 31, 2018 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) ! Quote
Tharwat Posted August 31, 2018 Posted August 31, 2018 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. Quote
Roy_043 Posted September 1, 2018 Posted September 1, 2018 (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 September 2, 2018 by Roy_043 Quote
Tharwat Posted September 1, 2018 Posted September 1, 2018 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. Quote
Recommended Posts
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.