Change XREF Layer Colors to One Color

Here is a great lisp routine that lets you simply select an XREF and change all of the XREF’s layers to a specific color (color 253 in this case).

This is useful in some of my work’s drawings because we work with existing conditions as an XREF to the “Proposed” design which is also an XREF. To make the “Proposed” drawing have a good contrast while both drafting and printing, we override the existing drawing XREF’s colors on color 253. With this LISP routine, we can easily do so in one click (as shown below).

~enjoy


;;; Changes the selected XREF's Layer color to AutoCAD Color 253 in the current drawing only
;;; Useful for Existing Base (E-Base) XREFs
(defun c:XR253	(/ xr1 xr2 xr3 xr4 xr5 xr6 tx1 tb1)
  (if (setq
	xr1 (entsel "\nSelect Xref to change all layers to color 253: ")  ;; <--- Change color number as needed
      ) ;_ end of setq
    (progn
      (setq xr2 (entget (car xr1)))
      (setq tx1 (cdr (assoc 0 xr2)))
      (if (and (= tx1 "INSERT")
	  ) ;_ end of and
	(progn
	  (setq xr3 (cdr (assoc 2 xr2)))
	  (setq xr4 (tblsearch "block" xr3))
	  (if (setq xr5 (cdr (assoc 1 xr4)))
	    (progn
	      (setq xr6 (strcat xr3 "|*"))
	      (command "-layer" "c" "253" xr6 "")  ;;; <---Change color number as needed
	    ) ;_ end of progn
	    (prompt (strcat "\n" xr3 " is not an X-Ref."))
	  ) ;_ end of if
	) ;_ end of progn
	(prompt "\nNo valid XREF selected")
      ) ;_ end of if
    ) ;_ end of progn
    (princ " ...Nothing selected")
  ) ;_ end of if
  (princ)
) 
Advertisements

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, AutoLISP XREFs, XREFs. Bookmark the permalink.

4 Responses to Change XREF Layer Colors to One Color

  1. Wayne Westwood says:

    Thankyou. This will save lots of time going through changing all the colours to grey.

  2. Gerald Heizelman says:

    Works great!! However it will turn on any layers that have been turned off.Any way to prevent that?

  3. ottocader says:

    Great routine! But it looks like the online source code is missing the backslash in front of the “n” characters at the beginning of the “entsel” and two “prompt” functions. I’m sure that the intent was to have the prompts displayed on a new line (“\n”) on the command line when running the routine.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s