Change layer color

Change layer color

Oh_Snap!
Enthusiast Enthusiast
2,239 Views
6 Replies
Message 1 of 7

Change layer color

Oh_Snap!
Enthusiast
Enthusiast

I've been using this lisp I found somewhere on the internet to change a layer color by picking an object on the layer and the color dialog appears and I select new color.  This dialog only has index colors though. Does anyone know if this could be modified to also include True Colors?

 

(defun C:xlc (/ lay col)
  (setq
    lay (cdr (assoc 8 (entget (car (nentsel "\nObject on Layer to assign color to: ")))))
    col (acad_colordlg (cdr (assoc 62 (tblsearch "layer" lay))) nil)
  )
  (command "_.layer" "_color" col lay "")
  (princ)
)
0 Likes
Accepted solutions (2)
2,240 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

....

  col (acad_truecolordlg (assoc 62 (tblsearch "layer" lay)) nil (assoc 62 (tblsearch "layer" lay)))

....

 

EDIT:  But using  what that returns is another matter....  It won't work to just substitute that line.  I'll have to think about that one.  [And I didn't replace my trial "0" layer name with 'lay' in both places -- fixed now.]

 

Further EDIT:  Minimally tested:

(defun C:xlc (/ lay col)
  (setq
    lay (cdr (assoc 8 (entget (car (nentsel "\nObject on Layer to assign color to: ")))))
    col (acad_truecolordlg (assoc 62 (tblsearch "layer" lay)) nil (assoc 62 (tblsearch "layer" lay)))
  ); setq
  (entmod (append (entget (tblobjname "layer" lay)) col))
  (princ)
); defun 

 

Kent Cooper, AIA
Message 3 of 7

ronjonp
Advisor
Advisor
Accepted solution

Try this:

(defun c:clc (/ c d e n)
  ;; RJP » 2019-03-19
  ;; Set layer color by pick
  (or (getenv "clc") (setenv "clc" "(62 . 1)"))
  (cond	((setq c (acad_truecolordlg (read (getenv "clc"))))
	 (setenv "clc" (vl-prin1-to-string (last c)))
	 (setq d (vla-get-activedocument (vlax-get-acad-object)))
	 (while	(setq e (car (nentsel "\nSelect entity to change layer color: ")))
	   (entmod (append (entget (tblobjname "layer" (cdr (assoc 8 (entget e))))) c))
	   (vla-regen d acactiveviewport)
	 )
	)
  )
  (princ)
)
(vl-load-com)
Message 4 of 7

Oh_Snap!
Enthusiast
Enthusiast

That works great!  Thank you Kent.

0 Likes
Message 5 of 7

Oh_Snap!
Enthusiast
Enthusiast

This also works. Thank you. 

0 Likes
Message 6 of 7

ronjonp
Advisor
Advisor

@Oh_Snap! 

You might give my code a try .. it has quite a bit more error checking and will remember your last color used 😉

*EDIT .. you did try it! 🙂

0 Likes
Message 7 of 7

York13
Explorer
Explorer

Is there a way to also have this LISP work with non-xrefed objects too?

 

Edit: Nevermind.  It appears to work just fine. Thanks.

Double Edit: Now I keep receiving an error Application ERROR: Bad arguments.

0 Likes