LISP Routine to Change ALL
Can someone provide me a basic routine to change ALL layers that have the color 'GREEN' to color 104. Doesn't matter what layers they are on (i.e. '0', 'text', 'tblock'), our office standards have switched from 'GREEN' to '104' in color.So maybe just a routine that I can add to my startup routine to change ALL layers that are GREEN to 104 immediately upon opening a drawing.
I have racked my brain searching for a routine or even bits and pieces to create my own lisp to solve my problem. Thanks Try this .
(defun c:To104 (/ l e) (while (setq l (tblnext "LAYER" (not l))) (if (eq 3 (cdr (assoc 62 (setq e (entget (tblobjname "LAYER" (cdr (assoc 2 l)))))))) (entmod (subst '(62 . 104) (assoc 62 l) e)) ) )(princ)) Hey Tharwat,
Thanks for chiming in, unfortunately when I run command, it returns nothing at all. No results. Sorry. Maybe something is missing? Hey my apologies, I misspoke when I requested the routine. The routine works, it changes the layers in the layer manager from green to 104 but I meant I also needed to change the objects and text and stuff within the drawing that have the color set to GREEN changed to 104.
My apologies for the confusion!!! Thanks look forward to your reply! For instance right now what I am having to do when I enter a drawing is isolate the TEXT layer, select all and change to another layer with 104 color. I have a routine I wrote for that. simple. Then I do 'BEDIT' and click on my titleblock (with attributes), then I select all the text thats on LAYER 0 but on COLOR 3 and CHANGE TO TEXT layer with 104 as color. I click close block editor, then run 'BATTMAN' and click 'sync' then ok!
This seems like I can automate this with a better solution! THANKS! Try this routine and let me know how things went on with you .
(defun c:Test (/ doc *error* ColorTo104 lst s) ;; Author : Tharwat AL Shoufi ;; ;; www.CadTutor.com 11.Oct.2013 ;; (or doc (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) ) (defun *error* (u) (if lst (foreach it lst (vla-put-lock (vla-item (vla-get-layers doc) it) :vlax-true) ) ) (princ "\n *Cancel*") ) (defun ColorTo104 (ent) (if (eq 3 (vla-get-color ent)) (vla-put-color ent 104) ) ) (vlax-for l (vla-get-layers doc) (ColorTo104 l) (if (eq :vlax-true (vla-get-lock l)) (progn (vla-put-lock l :vlax-false) (setq lst (cons (vla-get-name l) lst)) ) ) ) (vla-startUndomark doc) (vlax-for b (vla-get-blocks doc) (if (and (eq :vlax-false (vla-get-IsXref b)) (eq :vlax-false (vla-get-IsLayout b)) ) (vlax-for x b (ColorTo104 x) ) ) ) (if (ssget "_X" '( (-4 . "") ) ) (progn (vlax-for e (setq s (vla-get-ActiveSelectionSet doc)) (if (and (eq (vla-get-objectname e) "AcDbBlockReference") (eq :vlax-true (vla-get-hasattributes e)) ) (foreach att (vlax-invoke e 'GetAttributes) (ColorTo104 att) ) (ColorTo104 e) ) ) (vla-delete s) ) ) (if lst (foreach u lst (vla-put-lock (vla-item (vla-get-layers doc) u) :vlax-true) ) ) (vla-regen doc AcActiveViewport) (vla-EndUndoMark doc) (princ))(vl-load-com) Tharwat, why not filter the selection?
(ssget "_X" '( (-4 . "") ) )
Thank you jdiala for the suggestion , honestly I tried to add that filter to the ssget function but all my tries failed .
Codes updated . You are a saint! :notworthy::notworthy:
WORKED FLAWLESSLY!!! Now thanks to you a 1-2 minute routine in a drawing takes milliseconds with the type of my shortcut!!
I am decent when it comes to editing and manipulating certain routines but am totally unfamiliar with the VLAX, VLA, etc.... its gibberish to me. But hey I am still young and I learn new things everyday. One day I will be as good as you!!
GOD BLESS YOU AND THANK YOU THANK YOU THANK YOU!! PROPS!!!
Excellent , You're very welcome.
I am very happy for you too .
页:
[1]