Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp Routine To Change Layer Color

12 REPLIES 12
Reply
Message 1 of 13
jbrazier
6344 Views, 12 Replies

Lisp Routine To Change Layer Color

I am looking for a lisp routine to search the layer table to find a particular layer color and chamge color.

jbrazier@o-n.com
Jon Brazier
Director of Production Technology
O'Donnell & Naccarato
Philadelphia, Pa.
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: jbrazier

You should try writing it. It's a fairly straightforward job, and a good one
on which to learn a little coding. HINT: take a look at (tblnext...),
(tblobjname...) and (entmod...) functions.
___

"jbrazier" wrote in message
news:f166585.-1@WebX.maYIadrTaRb...
> I am looking for a lisp routine to search the layer table to find a
particular layer color and chamge color.
> jbrazier@o-n.com
>
Message 3 of 13
Anonymous
in reply to: jbrazier

jbrazier:

(defun VxChgLayCol (Old New / AcdDoc)
(vla-load-com)
(setq AcdDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(vlax-for Obj (vla-get-Layers AcdDoc)
(if (= (vla-get-Color Obj) Old)
(vla-put-Color Obj New)
)
(vlax-release-object Obj)
)
(vlax-release-object AcdDoc)
(princ)
)

(VxChgLayCol 3 7)
change all green layers to white...

Cheers
--
Juerg Menzi
MENZI ENGINEERING GmbH, Switzerland
http://www.menziengineering.ch
Message 4 of 13
Anonymous
in reply to: jbrazier

Sorry Paul, have seen your message to late... you're
right it's an easy job and a good example to learn a
little bit about programming lisp.

Cheers
--
Juerg Menzi
MENZI ENGINEERING GmbH, Switzerland
http://www.menziengineering.ch
Message 5 of 13
Anonymous
in reply to: jbrazier

I need a hint on how to get this to run.
Thanks,

"Jürg Menzi" wrote in message
news:3ECCE7BE.F42E5C41@bluewin.ch...
> jbrazier:
>
> (defun VxChgLayCol (Old New / AcdDoc)
> (vla-load-com)
> (setq AcdDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
> (vlax-for Obj (vla-get-Layers AcdDoc)
> (if (= (vla-get-Color Obj) Old)
> (vla-put-Color Obj New)
> )
> (vlax-release-object Obj)
> )
> (vlax-release-object AcdDoc)
> (princ)
> )
>
> (VxChgLayCol 3 7)
> change all green layers to white...
>
> Cheers
> --
> Juerg Menzi
> MENZI ENGINEERING GmbH, Switzerland
> http://www.menziengineering.ch
Message 6 of 13
Anonymous
in reply to: jbrazier

TEW or whatever you're called

copy - paste the code to a .lsp file load the file by 'appload' and start
the sequence as described.


Cheers
--
Juerg Menzi
MENZI ENGINEERING GmbH, Switzerland
http://www.menziengineering.ch
Message 7 of 13
Anonymous
in reply to: jbrazier

Thank you, this will be very handy someday. When I learn how to "start the
sequence as described". I know about the part leading up to



"Jürg Menzi" wrote in message
news:3ECD25AB.6844E3DF@bluewin.ch...
> TEW or whatever you're called
>
> copy - paste the code to a .lsp file load the file by 'appload' and start
> the sequence as described.
>
>
> Cheers
> --
> Juerg Menzi
> MENZI ENGINEERING GmbH, Switzerland
> http://www.menziengineering.ch
Message 8 of 13
Anonymous
in reply to: jbrazier

Maybe this is what you are after:

The command name is CH-COLOR37 means that will change all the color 3 to 7,
it makes sense now?

(defun C:CH-COLOR37 () (VxChgLayCol 3 7))

Now if you need let say all magenta to cyan [6 to 4] what you will do?

(defun C:CH-COLOR64 () (VxChgLayCol 6 4))

And so on....

Much easier no?

Best regards,
Luis Esquivel

http://www.draftteam.com
Enhance your AutoCAD(R) drafting with DraftTeam.


"TEW" wrote in message
news:189FBB803B43661CFE3170DEA6414A00@in.WebX.maYIadrTaRb...
> Thank you, this will be very handy someday. When I learn how to "start the
> sequence as described". I know about the part leading up to
lesson>
>
>
>
> "Jürg Menzi" wrote in message
> news:3ECD25AB.6844E3DF@bluewin.ch...
> > TEW or whatever you're called
> >
> > copy - paste the code to a .lsp file load the file by 'appload' and
start
> > the sequence as described.
> >
> >
> > Cheers
> > --
> > Juerg Menzi
> > MENZI ENGINEERING GmbH, Switzerland
> > http://www.menziengineering.ch
>
>
Message 9 of 13
Anonymous
in reply to: jbrazier

Thank you,
TEW
"Luis Esquivel" wrote in message
news:716C145B15B67965CDE077408E7048E0@in.WebX.maYIadrTaRb...
> Maybe this is what you are after:
>
> The command name is CH-COLOR37 means that will change all the color 3 to
7,
> it makes sense now?
>
> (defun C:CH-COLOR37 () (VxChgLayCol 3 7))
>
> Now if you need let say all magenta to cyan [6 to 4] what you will do?
>
> (defun C:CH-COLOR64 () (VxChgLayCol 6 4))
>
> And so on....
>
> Much easier no?
>
> Best regards,
> Luis Esquivel
>
> http://www.draftteam.com
> Enhance your AutoCAD(R) drafting with DraftTeam.
>
>
> "TEW" wrote in message
> news:189FBB803B43661CFE3170DEA6414A00@in.WebX.maYIadrTaRb...
> > Thank you, this will be very handy someday. When I learn how to "start
the
> > sequence as described". I know about the part leading up to
> lesson>
> >
> >
> >
> > "Jürg Menzi" wrote in message
> > news:3ECD25AB.6844E3DF@bluewin.ch...
> > > TEW or whatever you're called
> > >
> > > copy - paste the code to a .lsp file load the file by 'appload' and
> start
> > > the sequence as described.
> > >
> > >
> > > Cheers
> > > --
> > > Juerg Menzi
> > > MENZI ENGINEERING GmbH, Switzerland
> > > http://www.menziengineering.ch
> >
> >
>
>
Message 10 of 13
TylerMelancon
in reply to: Anonymous

Been searching around finally found something and I need this to work, it is what I am currently looking for, Our new office standards went from 'Green' to '104' and have different layers such as 'tblock' and '0' or 'text' all with this color 'green' that I need batch changed to 104.

 

Basically doesnt matter what the layer is called, if the color is GREEN it needs to be 104 now which is more on the hunter green instead of a lime green.

 

Anyways, I am stumped how to get this routine pieced together to perform properly.

 

Any help?!?!

Message 11 of 13
hmsilva
in reply to: TylerMelancon

change the command name as you desire (after the c: )

;; by Juerg Menzi
;; http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Lisp-Routine-To-Change-Layer-Color/m-...
(defun VxChgLayCol (Old New / AcdDoc)
 (vl-load-com)
 (setq AcdDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
 (vlax-for Obj (vla-get-Layers AcdDoc)
 (if (= (vla-get-Color Obj) Old)
 (vla-put-Color Obj New)
 )
 (vlax-release-object Obj)
 )
 (vlax-release-object AcdDoc)
 (princ)
 )

(defun c:chcolor104 () (VxChgLayCol 3 104));; change the command name

EDIT: If you're not used to using lisp files, this tutorial from Lee Mac may be useful...

 

HTH

Henrique

EESignature

Message 12 of 13
TylerMelancon
in reply to: hmsilva

Hey my apologies, I misspoke when I requested the routine. The routine works perfectly, it changes the layers in the layer manager from green to 104 HOWEVER 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. That is what I really really need! The text and objects on layer green to be converted to 104!

My apologies for the confusion!!! Thanks look forward to your reply! GOD BLESS

Message 13 of 13

Someone was able to squeeze me in their busy day and write something for me Here it is, You may Tweak to your liking I would assume, as long as you keep Tharwat AL Shoufi as PROPS HOLDER! God bless...

 

(defun c:104C (/ 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)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost