Quick Switch Color Scheme - AutoCAD Electrical

  • Posted November 26, 2007

    by Nate Holt

    Maybe you prefer a light background instead of the classic coal-black environment. The problem is that some of the AutoCAD Electrical layer color defaults don't show up too well when you're working with a white background -- some of the yellow and light cyan ones just don't stand out very well.

    Here's a quick work-around. An AutoLISP utility that you can set up to re-assign default layer colors to a handful of the more troublesome layer colors. Download it here: files/20401_20500/20415/file_20415.lsp

     Setup

    Open this AutoLISP file with a standard ASCII text editor or with the built-in Visual Lisp editor (type vlide [Enter] at the "Command:" prompt).  Near the top of the file you'll see this block of code:

      (setq layer_mapping
        (list  ; format is (list layernam newcolor)
          (list "WIRENO" 72) ; light green (70) --> shade darker
          (list "WIREFIXED" 7) ; light blue (130) --> black/white
          (list "WIREREF" 52) ; light green (61) --> darker olive green
          (list "WIREREF_DEST" 52) ; light green (61) --> darker olive green
          (list "MISC" 7) ; yellow --> black/white
          (list "PMISC" 7) ; yellow --> black/white
          (list "PTAG" 150) ; light yellow (51) --> medium blue
          (list "TAGS" 150) ; light yellow (51) --> medium blue
          (list "TERMS" 123) ; cyan --> gray/blue
      ) )

    Adjust this list or add in additional standard AutoCAD Electrical layers that you want to map to a different color. The color number is the last entry in each sublist. For example, the first entry, (list "WIRENO" 72) will instruct this utility to look for layer "WIRENO" in the active drawing and force its default color to be color 72.

    This utility also has provision to add in missing layers. Here is the section of the program that checks for missing WIRENO and WIREFIXED layers. If either is missing from the active drawing, it adds the layer and assigns the encoded color and line type. You might expand this list to add in your custom wire layer names.

      (setq layer_restore
        (list  ; format is (list layername color linetype)
          (list "WIRENO" 72 "Continuous")
          (list "WIREFIXED" 7 "Continuous")
        )
      )

    How it works

    Here is the full listing of the utility (below). The first third or so deals with defining what layers are to be processed. Then it gets down to business. The program cycles through all of the layer names found in the active drawing, the "tblnext" call. For each layer it finds, it checks to see if that layer name shows up in your "layer_mapping" list. If a match is found in your list, the utility compares the existing layer's color number with the one you've defined in the list. If different, the utility triggers the "LAYER" command to run (command line version) and feeds it the layer name and the new color assignment.

    After the existing layers are processed, it does the final check for missing layers. For each layer you've defined in the "layer_restore" list, it checks to see if that layer exists in the active drawing. If not found, it triggers the "LAYER" command again and adds it in ( ! ).

    (defun c:acelayer ( / flag ed x rec laynam layer_mapping layer_restore)
      ; PURPOSE: adjust default layer color assignments for switch to light background.
      ;    For example, change yellow-color layers to a color that displays better on a
      ;    white or light background. Also restore WIRENO and WIREFIXED layers and color
      ;    assignments if these two layers appear to have been purged from the drawing.
      ;
      (setq layer_mapping
        (list  ; format is (list layernam newcolor)
          (list "WIRENO" 72) ; light green (70) --> shade darker
          (list "WIREFIXED" 7) ; light blue (130) --> black/white
          (list "WIREREF" 52) ; light green (61) --> darker olive green
          (list "WIREREF_DEST" 52) ; light green (61) --> darker olive green
          (list "MISC" 7) ; yellow --> black/white
          (list "PMISC" 7) ; yellow --> black/white
          (list "PTAG" 150) ; light yellow (51) --> medium blue
          (list "TAGS" 150) ; light yellow (51) --> medium blue
          (list "TERMS" 123) ; cyan --> gray/blue
      ) )
     
      (setq layer_restore
        (list  ; format is (list layername color linetype)
          (list "WIRENO" 72 "Continuous")
          (list "WIREFIXED" 7 "Continuous")
        )
      )
      (setvar "CMDECHO" 0)
      (setq flag T) ; flag to rewind to beginning of LAYER table
      (while (/= (setq ed (tblnext "LAYER" flag)) nil)
        (setq flag nil) ; clear the rewind flag
        (setq laynam (strcase (cdr (assoc 2 ed)))) ; forced to upper case
        ; Look for layer name match in "layer_mapping"
        (foreach rec layer_mapping
          (if (AND (= (car rec) laynam) ; found match on name
                   (/= (cadr rec) (cdr (assoc 62 ed)))) ; mismatch on color assignment
            (progn ; flip color assignment for this layer
              (command "_.LAYER" "_C")
              (command (itoa (cadr rec)))
              (command (car rec))
              (command "")
              (princ "\nLayer ")
              (princ (car rec))
              (princ " ")
              (princ (cdr (assoc 62 ed)))
              (princ " --> ")
              (princ (cadr rec))      
        ) ) )
      ) 
      ; restore any missing layers              
      (foreach rec layer_restore
        (setq laynam (car rec))
        (if (not (tblsearch "LAYER" laynam))
          (progn ; layer not found, create it now
            (command "_.LAYER" "_N" laynam "_C" (itoa (cadr rec)) laynam "_Ltype" (caddr rec) laynam "")
            (princ "\nRestored layer ")
            (princ laynam)
            (princ " color=")
            (princ (cadr rec))
            (princ " ltype=")
            (princ (caddr rec))
      ) ) )     
      (princ)

     

    Load and Run

    1. Download the file from the link above.

    2. APPLOAD the file.

    3. Type ACELAYER [Enter] at the "Command:" prompt.

     

     

    0 Comment | Add Comment

Comments



You must be logged in to post a comment.

Login

Register now to access tips, discussions and more.
Forgot your password ?

Tags

You must be logged in to add a tag.

Send to a Peer

You must login to share pages.

Feedback

Tell us what you think of the site.

Send Feedback