Results 1 to 8 of 8

Thread: Changing color of Xref layers based on color and layer name

  1. #1
    Login to Give a bone
    0

    Default Changing color of Xref layers based on color and layer name

    Dear all,

    I am trying to find a way to change the color of Xref layers. Based on the original color of the layer in the original drawing.
    But this is giving me some troubles. At the moment i think i understand how i can cycle through the entire layer list. However i don't understand how the lisp can make the difference in layer colors and such...

    Is there anyone who is willing to help me upgragde my code a bit?

    So far i came up with:
    Code:
    (vl-load-com)
    (defun C:TEBXFADE () 
    (setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    (setq theLayers (vla-get-layers acadDocument))
    (setq i 0)
       (repeat (vla-get-count theLayers)
     (setq aLayer (vla-item theLayers i))
          (cond ((and (= vla-get-color 1) (= vla-get-name "*|*"))
            (vla-put-color alayer 251))
           ((and (= vla-get-color 2) (= vla-get-name "*|*"))
            (vla-put-color alayer 9))
           ((and (= vla-get-color 3) (= vla-get-name "*|*"))
            (vla-put-color alayer 8))
           ((and (= vla-get-color 4) (= vla-get-name "*|*"))
            (vla-put-color alayer 8))
           ((and (= vla-get-color 5) (= vla-get-name "*|*"))
            (vla-put-color alayer 8))
           ((and (= vla-get-color 7) (= vla-get-name "*|*"))
            (vla-put-color alayer 251))
           ((and (= vla-get-color 8) (= vla-get-name "*|*"))
            (vla-put-color alayer 252))
           ((and (= vla-get-color 9) (= vla-get-name "*|*"))
            (vla-put-color alayer 252))
           ((and (= vla-get-color 250) (= vla-get-name "*|*"))
            (vla-put-color alayer 252))
           ((and (= vla-get-color 251) (= vla-get-name "*|*"))
            (vla-put-color alayer 252))
           ((and (= vla-get-color 253) (= vla-get-name "*|*"))
            (vla-put-color alayer 254))
           (T (princ "\nNo Xref layers found"))
           (setq i (1+ i))
     );cond
       );repeat
    );defun

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Changing color of Xref layers based on color and layer name

    Here is a good start to begin with .

    Code:
    (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
          (cond ((and (= (vla-get-color layer) 1)(wcmatch (vla-get-name layer) "*|*"))
                       (vla-put-color layer 251))
                ((............;;; do the rest typical to the above two lines of code ....

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

    Default Re: Changing color of Xref layers based on color and layer name

    Code:
    (vl-load-com)
    
    (defun c:FOO (/ layerColor)
    
      ;; iterate the layer collection object
      (vlax-for oLayer (vla-get-layers
                         (vla-get-activedocument (vlax-get-acad-object))
                       )
    
        ;; if an xref layer
        (if (wcmatch (vla-get-name oLayer) "*|*")
    
          ;; conditionally check the existing layer color,
          ;; and change it if a match is found
          (cond ((vl-position
                   (setq layerColor (vla-get-color oLayer))
                   '(1 7)
                 )
                 (vla-put-color oLayer 251)
                )
                ((= 2 layerColor) (vla-put-color oLayer 9))
                ((vl-position layerColor '(3 4 5)) (vla-put-color oLayer 8))
                ((= 7 layerColor) (vla-put-color oLayer 251))
                ((vl-position layerColor '(8 9 250 251))
                 (vla-put-color oLayer 252)
                )
                ((= 253 layerColor) (vla-put-color oLayer 254))
          )
        )
      )
    )
    "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

  4. #4
    Login to Give a bone
    0

    Default Re: Changing color of Xref layers based on color and layer name

    Both are great!

    I am now using the one Render Man is posting and i'll try to update some new stuff in it like a selection set to decide which xref i want to change instead of all...

    Either case can someone explain me what the ' means in the piece of code ((vl-position layerColor '(3 4 5)) (vla-put-color oLayer )

    Thank you!

  5. #5
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Changing color of Xref layers based on color and layer name

    Quote Originally Posted by tuerlinckx_peter862162 View Post

    Either case can someone explain me what the ' means in the piece of code ((vl-position layerColor '(3 4 5)) (vla-put-color oLayer )
    The vl-position function would return a number indicating that the variable LAYERCOLOR is matching or is a member of the the list '(3 4 5) which means or give True sign to use the function
    vla-put-color to change the color of the object that held by the variable oLayer .

    Hope this help

  6. #6
    Login to Give a bone
    0

    Default Re: Changing color of Xref layers based on color and layer name

    so the '() means that everything between is a part of the list ...
    meaning in this case '(1 2 3 7 8 9) if the value from layercolors is either of the numbers in the list it will give a True and thus triggering the condition.

    It helps for a new lisp writer like me everything is still such a confusing part ...

  7. #7
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Changing color of Xref layers based on color and layer name

    Quote Originally Posted by tuerlinckx_peter862162 View Post
    ......... it will give a True and thus triggering the condition.
    Not exactly , but it will return an index , and that number ( index ) indicates to the position of that element ( symbol ) in the list .

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

    Default Re: Changing color of Xref layers based on color and layer name

    Quote Originally Posted by tuerlinckx_peter862162 View Post
    so the '() means that everything between is a part of the list ...
    meaning in this case '(1 2 3 7 8 9) if the value from layercolors is either of the numbers in the list it will give a True and thus triggering the condition.
    The QUOTE function is used here to tell LISP 'do not evaluate this list'.

    As the vl-Position statement serves as a test expression, within the COND statement, any non-Nil value returned (does not have to be True)... Which as Tharwat has already pointed out, is an integer representing the position the symbol is within the list... then the resultant expression (within that condition) is then evaluated.
    "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. Replies: 17
    Last Post: 2017-08-01, 01:12 AM
  2. assign layer lineweights based on layer color
    By viv.howe in forum AutoLISP
    Replies: 4
    Last Post: 2007-05-01, 04:27 PM
  3. assign layer lineweight based on layer color
    By kjbusacker in forum AutoLISP
    Replies: 9
    Last Post: 2007-03-01, 03:15 PM
  4. Lisp for changing layer color in XREF's
    By cadd4la in forum AutoLISP
    Replies: 5
    Last Post: 2005-09-28, 01:16 PM
  5. change layer without changing color
    By windowsxp5 in forum AutoCAD General
    Replies: 7
    Last Post: 2004-09-05, 09:24 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
  •