Results 1 to 6 of 6

Thread: changing layer colors

  1. #1
    Member
    Join Date
    2012-01
    Posts
    2
    Login to Give a bone
    0

    Default changing layer colors

    I get drawings that I need to tie new work in new areas to. Sometimes all the layers are one color. It is easier to tie to the existing drawing if specific layers are different colors. What I would like to do is automate the recoloring of these layers. For example if all the layers come in as white I want to change layer A to blue, layer B to red and layer F to yellow. The layers C,D,and E remain white. I have seen routines to change all layeres from one color to another color but that wont help me. Thank You.

  2. #2
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: changing layer colors

    Code:
    (defun c:chABCDEFlaycol ( / lnames obj )
    
      (vl-load-com)
    
      (setq lnames '("A" "B" "C" "D" "E" "F"))
      (foreach lname lnames
        (if (setq obj (vlax-ename->vla-object (tblobjname "LAYER" lname)))
          (cond
            ( (eq lname "A")
              (vlax-put-property obj 'Color 5)
            )
            ( (eq lname "B")
              (vlax-put-property obj 'Color 1)
            )
            ( (eq lname "C")
              (vlax-put-property obj 'Color 7)
            )
            ( (eq lname "D")
              (vlax-put-property obj 'Color 7)
            )
            ( (eq lname "E")
              (vlax-put-property obj 'Color 7)
            )
            ( (eq lname "F")
              (vlax-put-property obj 'Color 2)
            )
          )
        )
      )
      (princ)
    )
    HTH, M.R.

  3. #3
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,658
    Login to Give a bone
    0

    Default Re: changing layer colors

    Same layer names in each? A layer state may be the answer. Fix the layer colors in one drawing, save the layer state, export it, import it into the others.

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,095
    Login to Give a bone
    0

    Default Re: changing layer colors

    Quote Originally Posted by Tom Beauford View Post
    Same layer names in each? A layer state may be the answer. Fix the layer colors in one drawing, save the layer state, export it, import it into the others.

    Making certain the reference names (not filenames) of XREFs are the same, then you could use these layer states for other projects, too.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: changing layer colors

    If the layer names are consistent, then you can simply setup a drawing template with the correct layer color assignments, and insert & explode any received drawing into said template... Done.

    You can also use something such as LAYTRANS Command if you like.

    Cheers
    Last edited by BlackBox; 2014-10-15 at 07:47 PM. Reason: I can haz a spelling
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: changing layer colors

    Quote Originally Posted by marko_ribar View Post
    Code:
    (defun c:chABCDEFlaycol ( / lnames obj )
    
      (vl-load-com)
    
      (setq lnames '("A" "B" "C" "D" "E" "F"))
      (foreach lname lnames
        (if (setq obj (vlax-ename->vla-object (tblobjname "LAYER" lname)))
          (cond
            ( (eq lname "A")
              (vlax-put-property obj 'Color 5)
            )
            ( (eq lname "B")
              (vlax-put-property obj 'Color 1)
            )
            ( (eq lname "C")
              (vlax-put-property obj 'Color 7)
            )
            ( (eq lname "D")
              (vlax-put-property obj 'Color 7)
            )
            ( (eq lname "E")
              (vlax-put-property obj 'Color 7)
            )
            ( (eq lname "F")
              (vlax-put-property obj 'Color 2)
            )
          )
        )
      )
      (princ)
    )
    HTH, M.R.
    Slightly faster adaptation, which also supports UNDO functionality... Can also be easily ported to support ODBX with Document as parameter:

    Code:
    (vl-load-com)
    
    (defun c:FOO (/ *error* acDoc layerName)
    
      (defun *error* (msg)
         (if acDoc
           (vla-endundomark acDoc)
           )
         (cond ((not msg))                                                  ; Normal exit
               ((member msg '("Function cancelled" "quit / exit abort")))   ; <esc> or (quit)
               ((princ (strcat "\n** Error: " msg " ** ")))                 ; Fatal error, display it
         )
         (princ)
       )
    
      (vla-startundomark
        (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
      )
      (vlax-for x (vla-get-layers acDoc)
        (cond
          ((vl-position (setq layerName (vla-get-name x)) '("A"))
           (vla-put-color x 5)
          )
          ((vl-position layerName '("B")) (vla-put-color x 1))
          ((vl-position layerName '("C" "D" "E")) (vla-put-color x 7))
          ((vl-position layerName '("F")) (vla-put-color x 2))
        )
      )
    
      (*error* nil)
    )


    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. changing xref layer colors
    By mtubbs in forum AutoLISP
    Replies: 8
    Last Post: 2012-01-11, 11:49 PM
  2. Changing colors
    By Brian F. in forum Revit Architecture - General
    Replies: 2
    Last Post: 2009-08-17, 01:00 PM
  3. Changing colors
    By brethomp in forum NavisWorks - General
    Replies: 1
    Last Post: 2009-08-05, 01:19 PM
  4. LISP to change layer colors to random colors
    By mtubbs in forum AutoLISP
    Replies: 10
    Last Post: 2007-04-27, 05:39 AM
  5. Compare layer colors to pantone colors
    By gandre in forum AutoCAD LT - General
    Replies: 5
    Last Post: 2005-11-18, 01:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •