pman860507 Posted March 22, 2012 Posted March 22, 2012 Trying to get a routine going that changes the layer color. the issue that im having is if enter red for the color "red" I get this. Error: bad DXF group: (62 . "red") I'm running it though a getstring function. Im guessing that i need an integer as in 1. for it to work. so is there a way to convert "red" to the correct color code? I also realized that i will need to convert the string to integer if "40" is entered. Thanks Code is below. (defun C:Layer_Color ( / obj col lay layref layname cnt) (defun *error* ( msg ) (if (< 0 id) (unload_dialog id)) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (progn (princ (strcat "\nError: " msg)) (setq cnt T) (setq tmpEnt (tblnext "layer" cnt)) ) ) (princ) ) (while (= obj nil) (setq obj (entget(car(entsel "\nSelect Object:")))) (if (= obj nil) (princ "\nNo Object Selected."))) (setq lay (cdr(assoc 8 obj))) (while (or(= col nil)(= col "")) (setq col(getstring "\nNew Color:")) (if (or(= col nil)(= col "")) (princ "No color entered.\n") (princ "New color selected.\n") ) ) (while (/= layname lay) (setq layref (tblnext "layer")) (setq layname (cdr(assoc 2 layref))) ) (entmakex(list(assoc 0 layref)(cons 100 "AcDbSymbolTableRecord")(cons 100 "AcDbLayerTableRecord")(assoc 70 layref)(assoc 2 layref)(cons 62 col)(cons 6 "CONTINUOUS")(cons 290 1))) (setq cnt T) (setq tmpEnt (tblnext "layer" cnt)) (princ) ) Quote
MSasu Posted March 22, 2012 Posted March 22, 2012 Try to use a hard-coded association list; to ensure that your user provide an apropriate answer may look on INITGET function. (setq ColorsList '(("Red" . 1) ("Yellow" . 2) ("Green" . 3) [color=magenta]...[/color])) (initget "Red Yellow Green [color=magenta]...[/color]") (setq theColor (getkword "\nInput color: ")) (cons 62 (cdr (assoc theColor ColorsList))) Regards, Mircea Quote
pman860507 Posted March 22, 2012 Author Posted March 22, 2012 Yeah i though about that. Is it just the 7 main colors that are used like that? Or are there more? Quote
Tharwat Posted March 22, 2012 Posted March 22, 2012 Things like this .... ? (defun c:TesT (/ color e) ;;; Tharwat 22. march . 2012 ;;; (if (setq color (acad_colordlg 7 t)) (entmod (subst (cons 62 color) (assoc 62 (setq e (entget (tblobjname "LAYER" (getvar 'clayer)))) ) e ) ) (princ) ) (princ) ) Quote
MSasu Posted March 22, 2012 Posted March 22, 2012 Up to my knowledge only the first 7 colors are named in AutoCAD. However there is the list of named colors used in web design and you can "borrow" names from there as long your user is advised of this. Regards, Mircea Quote
David Bethel Posted March 22, 2012 Posted March 22, 2012 You may want to look into (acad_colordlg) It is quite useful. -David Quote
Tharwat Posted March 22, 2012 Posted March 22, 2012 Thanks worked out great. You're welcome happy to hear 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.