Jump to content
tmelancon

LISP Routine to Change ALL 'GREEN' layer colors to '104'! HELP!

Recommended Posts

tmelancon

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

Share this post


Link to post
Share on other sites
Tharwat

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

Share this post


Link to post
Share on other sites
tmelancon

Hey Tharwat,

 

Thanks for chiming in, unfortunately when I run command, it returns nothing at all. No results. Sorry. Maybe something is missing?

Share this post


Link to post
Share on other sites
tmelancon

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!

Share this post


Link to post
Share on other sites
tmelancon

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!

Share this post


Link to post
Share on other sites
Tharwat

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 . "<OR")
              (-4 . "<AND")
              (62 . 3)
              (-4 . "AND>")
              (-4 . "<AND")
              (0 . "INSERT")
              (66 . 1)
              (-4 . "AND>")
              (-4 . "OR>")
             )
     )
   (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)

Edited by Tharwat

Share this post


Link to post
Share on other sites
jdiala

Tharwat, why not filter the selection?

 

(ssget "_X" '(
               (-4 . "<OR")
                 (-4 . "<AND") (62 . 3) (-4 . "AND>")
                 (-4 . "<AND") (0 . "INSERT") (-4 . "AND>")
               (-4 . "OR>")
              )
 )

Share this post


Link to post
Share on other sites
Tharwat
Tharwat, why not filter the selection?

 

(ssget "_X" '(
               (-4 . "<OR")
                 (-4 . "<AND") (62 . 3) (-4 . "AND>")
                 (-4 . "<AND") (0 . "INSERT") (-4 . "AND>")
               (-4 . "OR>")
              )
 )

 

Thank you jdiala for the suggestion , honestly I tried to add that filter to the ssget function but all my tries failed .

 

Codes updated . :)

Share this post


Link to post
Share on other sites
tmelancon

You are a saint! :notworthy::notworthy::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!!!

Share this post


Link to post
Share on other sites
Tharwat
You are a saint! :notworthy::notworthy::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 . :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×