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

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.

20 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.

  4. Farid says:

    Thanks. What’s the best way to revert to normal?

    • AutoCAD Tips says:

      To Revert the Layers to display as they do in the XREFed file:
      Use the command VISRETAIN and set it to 0 (zero).
      Reload the XREF from the XREF Manager
      Use the command VISRETAIN and set it back to 1
      Note: VISRETAIN is a system variable is not a command, the reason I refer to it as a command is that you can change system variable in the commandline like a command.

  5. abhilash says:

    so were i will get the lisp

  6. VASILE CHIPER says:

    WERE CAN I DOWNLOAD THIS LISP ?

  7. James says:

    Thanks! working well

  8. Ck Novel says:

    Why I can’t Download Sir?

  9. ottocader says:

    Ck Novel, you can’t download this routine. You need to copy all the code below the animation near the top of this page, paste it into a blank page in a text editor and save it as XR253.LSP.

  10. Abhilash says:

    Works great! But if I want XREF colour 250 then what I want to do replace the 253 to 250?

    • ottocader says:

      That’s correct! Wherever you see 253 in the code, just replace it with 250 or whatever color number you would like to use. Any number from 0 to 255 will work.

  11. Nathan says:

    All of the entities in the XREF have to be color BYLAYER, right?

  12. Fatal Error! says:

    You are a genius!… Thank You!

Leave a comment