AutoCAD 2010/2011/2012

AutoCAD 2010/2011/2012

Reply
New Member
DEREKCOBB
Posts: 1
Registered: ‎08-25-2011
Message 1 of 4 (1,442 Views)

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

1442 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

 

*Expert Elite*
azrdgldr
Posts: 1,250
Registered: ‎01-09-2007
Message 2 of 4 (1,433 Views)

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.

*Expert Elite*
ToanDN
Posts: 1,893
Registered: ‎09-26-2006
Message 3 of 4 (1,416 Views)

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.

Active Contributor
cadhelp
Posts: 44
Registered: ‎03-30-2004
Message 4 of 4 (1,389 Views)

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

)

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.