Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

Yeah i though about that. Is it just the 7 main colors that are used like that? Or are there more?

Posted

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

Posted

You may want to look into (acad_colordlg) It is quite useful. -David

Posted
Thanks worked out great.

 

You're welcome :)

 

happy to hear 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...