Jump to content

Lisp colour change for all layers and blocks


hyposmurf

Recommended Posts

When we receive drawings from architects,we then only change the colour of thier layers so that ours stand out more.As we use colour dependant plot styles the best colour for architectual xrefs is colour 8.Sometimes we have blocks that are on the wrong layer and the only way to modify them is by using the modify in place xref command,individually altering the clour properties of each one.There an alternative method,to by just exploding them all but thats my last resort.Does anyone know of a lisp that will change all the layers of a drawing to one colour and that will also do this for all blocks to.Heres me hoping :)

I just found a lisp for it but doesnt seem to work,wont recognise the lisp?

; Changes the color of every entity in a drawing

; to BYLAYER, and changes all Layer colors to what

; you specify.

 

;(defun c:RICH ( / e d edata bdef bent ecl color)

(graphscr)

(setq ecl '(62 . 256))

(setvar "CMDECHO" 0)

(command "_.Layer" "unlock" "*" "")

(princ "\nModify Main Entities...")

(setq e (entnext))

(while e

(entmod (list (cons -1 e) ecl))

(setq e (entnext e))

)

(princ "\nModifying Block Entities... ")

(while (setq bdef (tblnext "block" (not bdef)))

(setq bent (cdr (assoc -2 bdef)))

(while bent

(entmod (list (cons -1 bent) ecl))

(setq bent (entnext bent))

)

)

(princ "\nRegenerating drawing... ")

(command "_.regenall")

(princ)

 

(COMMAND "AUDIT" "Y" )

(COMMAND "AUDIT" "Y" )

(PRINC)

Whats up,any ideas? :?

Link to comment
Share on other sites

I just learned in this Forum (here http://www.cadtutor.net/forum/viewtopic.php?t=504) to try the simple solutions first.

Hyposmurf

Is it too hard to select all objects in your DWG and use CHPROP to change they color to 8? Or use the properties window if you think it is more convenient.

Also in the "Layer properties manager" window you may select all the layers by pressing CTRL+A and modify they color from a snap.

Probable it is possible to write a Lisp for. But CADTutor will post a trick with a right-click or something and all the Forum will laugh on me :)

Link to comment
Share on other sites

I found another way to :D .Ive tried changing the colours by the properties and also from within the layers properties manager,but I still end up having to modify blocks that are not "by layer".A way around this is to use a lisp called "burst" that explodes the blocks and then converts the attributes to text(usually if you explode blocks you end with just attribute tags,which is not good).Still dont like the idea of exploding drawings but it seems to work fine,for this purpose,as the xref is then bound to form a block later on anyway.One thing that I used to always notice when people first start out using CAD is if theyre not sure how to modify any attributes they would just explode the block or drawing,which is really your last option.For such things as titleblocks this can be a messy way of doing things

Link to comment
Share on other sites

  • 5 years later...
  • 1 month later...
In newer CAD (2008 for sure) there's SETBYLAYER command which can be usful in changing all objects' properities to 'BY LAYER' (blocks, too)....

 

 

Yes! Awsome! I have needing something like this for a while! In my work, we take architectural plans and make everything color 8 so that the floor plans are in the background and our electrical shows up on top better.

 

Thanks kumbaya!

 

This could be helpful for anyone else needing to know, so this will act as a bump for it. :D

Link to comment
Share on other sites

In newer CAD (2008 for sure) there's SETBYLAYER command which can be usful in changing all objects' properities to 'BY LAYER' (blocks, too)....

 

You learn something new everyday!

 

Thanks Kumbaya - very handy when using newer CAD versions :)

Link to comment
Share on other sites

Type ColorX in command line

(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:COLORX ( / 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 ColorX in command line")

the latest version see # 14

Edited by VVA
Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...

This lisp can chnage the xref color which are in the block ,but is there any way can change the xref color which is not in block( not set by layer)? Is there anyone can help? tks

 

Type ColorX in command line

(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:COLORX ( / 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 ColorX in command line")

Link to comment
Share on other sites

This Lisp does not change xref. If you want to change xref, open it and use ColorX.

Sorry,VVA,I didn't get it.Maybe I misunderstood,but I already used ColorX which the lisp you posted before.But it still didn't change the overwrited color on the drawing which have xref(not the source drawing)

Looking forward your reply

thanks

Link to comment
Share on other sites

Probably we do not understand each other. Can be variable VISRETAIN will help for xref layer color?

And it is even better to publish a small example of that does not do ColorX

Link to comment
Share on other sites

Sorry for the confusing.Let me try to make it clear.What we want to achieve is when we make a new drawing base on a reference drawing(probably get from other company),and we want the reference drawing are all turn into be grey,so our drawing can be very clear.But unfortunately,we only can change the color which are bylayer,if the object color is not set bylayer propotion,it's won't change.

 

Attached pls find the small souring drawing (for test )& sample effect

 

Following are the test steps:

1.open a blanket drawing,then use xref command to attach the source drawing,

2.change the xref color in layer manager.choose grey

3.run the colorx command,you will find still some object not change the color yet.

 

 

And it would be better the lisp won't change the color of the current drawing,because right now ,when you run colorx,it will also affect the current drawing's block.we hope can chose the refernce drawing first then run the command.

 

 

BTW,visretain doesn't work,we tried.

 

Hope it's clear enough.

 

Thanks in advance

sample effect.pdf

sourcing drawing.dwg

Link to comment
Share on other sites

Command:

ColorX - change color all object of drawing. All layer unlock and thaw

ColorXREF change color xref only on a current session. All layer unlock and thaw

ColorXL - change color all object of drawing. Objects on the locked and frozen layers are ignored

ColorXREFL change color xref only on a current session. Objects on the locked and frozen layers are ignored

*** Add 20.03.2009 - Now ColorX ColorXREF work with Attrubutes

*** Add 31.03.2009 - Now ColorX and ColorXREF colored dimension (include radius).

*** Add 02.04.2009 - Change color Qleader, Mtext, Mleader. Add Simple progressbar

*** Add 19.20.2012 - minor changes to the code to be able to run in batch mode

In batch mode use function _colorx or _colorxref

Example

(_colorx 1 t) ;_change the color of all objects in red
(_colorx 1 nil) ;_change the color of all objects in red, except for objects on locked layers
(_colorxref 1 t) ;_change the color of all xref objects in red
(_colorxref 1 nil) ;_change the color of all xref objects in red, except for objects on locked layers

Links to other useful commands

 

BLCC - Changes color of the chosen blocks

ENCC - Changes color of the chosen objects (may be element of the block)

ColorA - Changes in the color of selected items in the area

COLORXLAY - changes xref layer colors

COLORFL - Color From Layer

PFL - Properties From Layer

Attcol - Attribute Color

 

If you want to operate colour of xref objects in the blanket drawing:

1. Open Xref (sourcing drawing.dwg)

2. Run ColorX and set color bylayer

3.open a blanket drawing

4. Creat layer "Xref"

5. Set layer "Xref" current

6 use xref command to attach the source drawing (sourcing drawing.dwg)

7.change the xref color in layer manager. choose grey

NOTE. If some objects in xref (sourcing drawing.dwg) are placed on a layer 0 your mast change layer of an insert of the external reference in a blanket drawing to grey too. (layer "XREF")

I do not know as this technical term sounds in English. I translate from Russian: there Is an emersion of a layer 0. All objects located on 0 layer in drawing of the external reference (sourcing drawing.dwg) inherit properties of a external reference layer in blanket drawing (layer "XREF")

colorx.LSP

Edited by VVA
minor changes to the code
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thanks a lot!VVA,that's excellent,problem been sloved!!

One more small request,when I run colorxref now,it will effect all the xref color.What if I want to lock one layer color,don't be affect by colorxref.Is that possible?

 

Thanks again!

Link to comment
Share on other sites

One more small request,when I run colorxref now,it will effect all the xref color.What if I want to lock one layer color,don't be affect by colorxref.Is that possible?

Adds some commands in #14

Link to comment
Share on other sites

Hi VVa ,

Sorry, we meet a new problem today,when we bind the current drawing with source drawing,the source drawing(grey one)will lost.Can you help us to slove this problem?

tks

Adds some commands in #14
Link to comment
Share on other sites

I bind grey source drawing and all ok.

1. What color of your Model tab background?

2. If to use CTRL+A that something is selected?

PS.

From my practice.

Colour of model Model tab background set to True color 0,0,0.

Insert xref by black colour. Xref on model tab it is not visible, but it was selected on CTR+A.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...