• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    AutoCAD 2010/2011/2012 DWG Format

    Reply
    New Member
    DEREKCOBB
    Posts: 1
    Registered: ‎08-25-2011

    Script or Lisp to locate Layers by colors and change to perferred colors

    874 Views, 3 Replies
    08-26-2011 07:36 AM

    We receive drawings that use many colors for layers which print oddly when using our .CTB file.  I need to be able to automatically find all layers of a certain color and change these layers color to one that will plot correctly for us.  Example: if several layers are set to bylayer color 30, it would find all of them and change the layer color to red or whatever we prefer.  This would be great to be able to set up a table that would go through all the layers and save the selection set for each color and change only those, so if we want their RED for be YELLOW it won't select those we just changed to RED and make them YELLOW.

    There's vs. Ours

    MAGENTA TO YELLOW

    GREEN TO WHITE

    YELLOW TO GREEN

    BLUE TO RED

     

    Please use plain text.
    *Expert Elite*
    Posts: 1,242
    Registered: ‎01-09-2007

    Re: Script or Lisp to locate Layers by colors and change to perferred colors

    08-26-2011 08:40 AM in reply to: DEREKCOBB

    You could use a layer property filter set to the color you want to change but if you have a lot of layers of color to change, this could be a tedious task.  Search in the lisp forum to see if there may be a program all ready written if not then post a request there, maybe some there could write one for you.

    Please use plain text.
    *Expert Elite*
    ToanDN
    Posts: 1,839
    Registered: ‎09-26-2006

    Re: Script or Lisp to locate Layers by colors and change to perferred colors

    08-26-2011 02:24 PM in reply to: DEREKCOBB

    You could setup a CAD Standard to check their drawings and the color of certain layer to match the standard.  I could be wrong but I don't think it will detect the color A and change to color B globally, but change color of a layer from A to B.  Meanwhile, you can always ask for their CTB to use when plotting their drawings.

    Please use plain text.
    Active Contributor
    Posts: 44
    Registered: ‎03-30-2004

    Re: Script or Lisp to locate Layers by colors and change to perferred colors

    08-29-2011 11:39 AM in reply to: DEREKCOBB

    ;; this will replace colors for layers, and nested objects

    ;; find this line in the code and update it to fit yor CTB (setq Color-list '((4 7)(OldColor NewColor)(15 7)))


     

    (defun update-colors-to-CTB ( / lay-obj color layers Block Blocks)
    
      
     (setq Color-list '((4 7)(15 7)))
    
    ;;; step 1 update LAYERS for a new color
     (setq layers (vla-get-layers  (vla-get-activedocument(vlax-get-acad-object))))
    ;;; update layers
     (vlax-for lay-obj layers
      (if(setq color(assoc(vla-get-Color lay-obj)Color-list))
       (vla-put-Color lay-obj (last color))
      )
     )
    
    ;;; 2 update BLOCKS for a new color  
     (setq Blocks (vla-get-Blocks (vla-get-activedocument(vlax-get-acad-object))))
    ;;; update objects
     (vlax-for Block Blocks
      (vlax-for obj Block
       (if(setq color(assoc(vla-get-Color obj)Color-list))
        (vla-put-Color obj (last color))
       )
      )
     )
    
    (princ "Do not forget to update dim styles, Leaders and MLeaders")
    
    )

     

    Please use plain text.