View Full Version : Color Change Routine - Layers & Objects
pastorfortune
2006-12-06, 03:35 AM
Our company recently changed plot styles. There are about a dozen colors that need to be updated in each of the old drawings. I can easily create a batch file to run on a large amount of drawings at once. I know all of the color numbers that are old and what the new color numbers need to be. I am new to lisping and simply need a lisp routine that will query all the layers in a drawing and change the layer color from one color to another (e.g. 51 to 55). I also need the routine to check all objects in the drawing with a color override (color set to something other than bylayer) and apply the change as well. If I have the meat of the routine, I can put the color numbers in as needed. And I would like to understand the lisp routine fully so I can write it from scratch in the future.
Thanks in advance for any who can help
kpblc2000
2006-12-06, 07:00 AM
I see 2 variants of the decision of a problem.
1. To make automatically loaded lisp (it also is automatically started on performance) which at the moment of start checks all entities and layers of the current file and changes them. It is possible to name the positive party (relative, certainly) simplicity of the decision and start only at the moment of necessity. The negative party will be, that processing only the current file is carried out.
2. To make lisp which it is consecutive from the specified folder will carry out opening a file, its change, preservation of changes and closing of it. A positive element that start (at least theoretically) will be carried out only once. The negative party: at receipt of files from the foreign design organizations it is required to carry out again this lisp.
What variant is more preferable?
For example, 1st variant is somthing like this:
;; list of color comformity: (<old color> . <new color>)
(setq lst_color '((1 . 16)
(2 . 20)
(51 . 55)
)
) ;_ end of setq
(defun normcolors (/ *error*
*kpblc-activedoc* _kpblc-layer-status-save
_kpblc-layer-status-restore
_kpblc-error-catch tmp
)
(defun *error* (msg)
(_kpblc-layer-status-restore)
(vla-endundomark *kpblc-activedoc*)
(princ msg)
(princ)
) ;_ end of defun
(defun _kpblc-error-catch (protected-function
on-error-function
/
catch_error_result
)
(setq catch_error_result (vl-catch-all-apply protected-function))
(if (and (vl-catch-all-error-p catch_error_result)
on-error-function
) ;_ end of and
(apply on-error-function
(list (vl-catch-all-error-message catch_error_result))
) ;_ end of apply
catch_error_result
) ;_ end of if
) ;_ end of defun
(defun _kpblc-layer-status-restore (/ item)
(if *kpblc-list-layer-status*
(progn
(foreach item *kpblc-list-layer-status*
(_kpblc-error-catch
'(lambda ()
(vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item))))
) ;_ end of lambda
nil
) ;_ end of _kpblc-error-catch
(_kpblc-error-catch
'(lambda ()
(vla-put-lock (car item) (cdr (assoc "lock" (cdr item))))
) ;_ end of lambda
nil
) ;_ end of _kpblc-error-catch
) ;_ end of foreach
) ;_ end of progn
) ;_ end of if
(setq *kpblc-list-layer-status* nil)
) ;_ end of defun
(defun _kpblc-layer-status-save (layers-on / item)
(vlax-for item (vla-get-layers *kpblc-activedoc*)
(setq *kpblc-list-layer-status*
(append *kpblc-list-layer-status*
(list
(list item
(cons "freeze" (vla-get-freeze item))
(cons "lock" (vla-get-lock item))
) ;_ end of list
) ;_ end of list
) ;_ end of append
) ;_ end of setq
(if layers-on
(progn
(_kpblc-error-catch
'(lambda ()
(vla-put-freeze item :vlax-false)
) ;_ end of lambda
nil
) ;_ end of _kpblc-error-catch
(vla-put-lock item :vlax-false)
) ;_ end of progn
) ;_ end of if
) ;_ end of vlax-for
) ;_ end of defun
(vl-load-com)
(vla-startundomark
(setq *kpblc-activedoc* (vla-get-activedocument (vlax-get-acad-object)))
) ;_ end of vla-startundomark
(_kpblc-layer-status-save nil)
;; Changing layer colors
(vlax-for lay (vla-get-layers *kpblc-activedoc*)
(if (cdr (assoc (vla-get-color lay) lst_color))
(vla-put-color lay (cdr (assoc (vla-get-color lay) lst_color)))
) ;_ end of if
) ;_ end of vlax-for
;; Changing entity color
(vlax-for blk (vla-get-blocks *kpblc-activedoc*)
(if (not (vlax-property-available-p blk 'path))
(progn
(vlax-for ent blk
(if (cdr (assoc (vla-get-color ent) lst_color))
(vla-put-color ent (cdr (assoc (vla-get-color ent) lst_color)))
) ;_ end of if
) ;_ end of vlax-for
) ;_ end of progn
) ;_ end of if
) ;_ end of vlax-for
(_kpblc-layer-status-restore)
(vla-endundomark *kpblc-activedoc*)
(princ)
) ;_ end of defun
(normcolors)Set this routine as autoloaded :)
pastorfortune
2006-12-07, 01:24 AM
Absolutely Incredible! Thanks A Ton!!!
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.