brianfengming Posted December 3, 2020 Share Posted December 3, 2020 (edited) i intend to change the element color in specific layer. i find the lisp as follows. the lisp will change all objects color. is it possible to modify it to meet our requirement. ===QUO== ;Changes the colour of ;all objects in drawing ;icluding blocks and references ;;IT WILL CHANGE ALL REF ALSO MAKE BACKUP OF ALL REF BEFORE USING (defun mip:layer-status-restore () (foreach item *MIP_LAYER_LST* (if (not (vlax-erased-p (car item))) (vl-catch-all-apply '(lambda () (vla-put-lock (car item) (cdr (assoc "lock" (cdr item)))) (vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item)))) ) ;_ end of lambda ) ;_ end of vl-catch-all-apply ) ;_ end of if ) ;_ end of foreach (setq *MIP_LAYER_LST* nil) ) ;_ end of defun (defun mip:layer-status-save () (setq *MIP_LAYER_LST* nil) (vlax-for item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (setq *MIP_LAYER_LST* (cons (list item (cons "freeze" (vla-get-freeze item)) (cons "lock" (vla-get-lock item)) ) ;_ end of cons *MIP_LAYER_LST* ) ;_ end of cons ) ;_ end of setq (vla-put-lock item :vlax-false) (if (= (vla-get-freeze item) :vlax-true) (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false)))) ) ;_ end of vlax-for ) ;_ end of defun (defun ChangeAllObjectsColor (Doc Color ) (vlax-for Blk (vla-get-Blocks Doc) (if (= (vla-get-IsXref Blk) :vlax-false) (vlax-for Obj Blk (if (vlax-property-available-p Obj 'Color) (vla-put-Color Obj Color) ) ) ) ) ) (defun C:CX ( / doc col) (vl-load-com) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark doc) (mip:layer-status-save) (if (setq col (acad_colordlg 7 t)) (ChangeAllObjectsColor doc col);_ col � color number ) (mip:layer-status-restore) (vla-endundomark doc) (princ) ) (princ "\nType CX in command line") ==UNQUO== Edited December 3, 2020 by SLW210 Add Code Tags Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 4, 2020 Share Posted December 4, 2020 Ok so say change Lines, plines on layer abc correct ? Need to know which objects to change ? Could be like type "Line" or "*line" plines & Lines or "line Arc Circle" and so on. Quote Link to comment Share on other sites More sharing options...
pkenewell Posted December 4, 2020 Share Posted December 4, 2020 (edited) Note: The routine you submitted updates just objects in block definitions, not inserts or other objects. If that is what you actually want, the solution is simple: Change the following line in the "ChangeAllObjectsColor" function: (if (vlax-property-available-p Obj 'Color) To (if (and (vlax-property-available-p Obj 'Color)(= (vla-get-layer obj) "<Your Layer Name Here>")) ;; Replace "<Your Layer Name Here>" with the layer name you need. Edited December 4, 2020 by pkenewell Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.