Results 1 to 9 of 9

Thread: Set all colours to 'By Layer'

  1. #1
    I could stop if I wanted to
    Join Date
    2008-06
    Location
    Adelaide, South Australia
    Posts
    279
    Login to Give a bone
    0

    Default Set all colours to 'By Layer'

    Before I start I should say that 'colours' DOES have a 'u' in it... I'm Australian...

    I'm looking for a script that I can run to set everything (including stuff in blocks) to 'by layer'.

    I'd rather not go through every drawing, explode or edit all the blocks and set the colours to 'by layer'.

    I heard that a script like this exists but have no idea where to find it. Anyone know?

    Rather not write the thing myself.

  2. #2
    I could stop if I wanted to
    Join Date
    2008-06
    Location
    Adelaide, South Australia
    Posts
    279
    Login to Give a bone
    0

    Default Re: Set all colours to 'By Layer'

    Nevermind, did it myself.

    Code:
    ;;;'By Layer' Reset - By Randy Rossi 2008
    ;;;Type 'bylayer' to start.
    ;;;Will not change XREFS, will change blocks as well as nested blocks.
    
    (defun c:bylayer() ;;;comment out this line to enable script to autorun when in startup suite
    	(command "setbylayer" "all" "" "yes" "yes")
    	(SETQ tm1 (GETVAR "TILEMODE"))
    	(IF (= Tm1 1)
    		(PROGN
    			(SETVAR "TILEMODE" 0)
    				(command "setbylayer" "all" "" "yes" "yes")
    			(SETVAR "TILEMODE" 1)
    		)
    	)
    
    	(SETQ tm1 (GETVAR "TILEMODE"))
    	(IF (= tm1 0)
    		(PROGN
    			(SETVAR "TILEMODE" 1)
    				(command "setbylayer" "all" "" "yes" "yes")
    			(SETVAR "TILEMODE" 0)
    		)
    	)
    ) ;;;comment out this line to enable script to autorun when in startup suite
    Yes, I know.... simple, didn't occur to me to use "setbylayer". Completely forgot about it.
    Last edited by schrodingerscat; 2008-10-09 at 01:36 AM.

  3. #3
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,288
    Login to Give a bone
    0

    Default Re: Set all colours to 'By Layer'

    Glad you could figure it out and share it with us.
    Also look at this thread which discusses this very issue, solved with a lisp routine someone posted.
    Ted
    ____________________________________________________________________ ________________
    Windows 10
    AutoCAD 2018 - REVIT 2019 - Inventor Professional 2017 (when I can)

  4. #4
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Set all colours to 'By Layer'

    Quote Originally Posted by schrodingerscat View Post
    I'm looking for a script that I can run to set everything (including stuff in blocks) to 'by layer'.
    You are aware of the SetByLayer command in recent versions of AutoCAD, aren't you?
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  5. #5
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Set all colours to 'By Layer'

    Quote Originally Posted by RobertB View Post
    You are aware of the SetByLayer command in recent versions of AutoCAD, aren't you?
    Brilliant ... another one for my little black book!
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  6. #6
    Active Member
    Join Date
    2007-03
    Posts
    57
    Login to Give a bone
    0

    Default Re: Set all colours to 'By Layer'

    Try it. Load and type in command line ColorX
    Code:
    (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 256 t))
      (ChangeAllObjectsColor doc  col);_ col — color number
        )
      (mip:layer-status-restore)
      (vla-endundomark doc)
      (princ)
      )
    (defun ChangeAllObjectsColor (Doc Color / tempObjType ColCnt RowCnt)
    (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 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

  7. #7
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,288
    Login to Give a bone
    0

    Default Re: Set all colours to 'By Layer'

    Quote Originally Posted by RobertB View Post
    You are aware of the SetByLayer command in recent versions of AutoCAD, aren't you?
    Which versions of Acad?
    I'm in 2006 and this command doesn't work.
    (wish it did..... )
    Ted
    ____________________________________________________________________ ________________
    Windows 10
    AutoCAD 2018 - REVIT 2019 - Inventor Professional 2017 (when I can)

  8. #8
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Set all colours to 'By Layer'

    Quote Originally Posted by RobertB View Post
    You are aware of the SetByLayer command in recent versions of AutoCAD, aren't you?
    Quote Originally Posted by tedg View Post
    Which versions of Acad?
    I'm in 2006 and this command doesn't work.
    (wish it did..... )
    2008 and above.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  9. #9
    All AUGI, all the time Norton_cad's Avatar
    Join Date
    2016-02
    Location
    Sydney, Australia
    Posts
    512
    Login to Give a bone
    0

    Default Re: Set all colours to 'By Layer'

    Quote Originally Posted by tedg View Post
    Which versions of Acad?
    I'm in 2006 and this command doesn't work.
    (wish it did..... )
    I have a couple of Lisp routines that will sort out any blocks & nested entities, and will work fine with 2006.
    Attached Files Attached Files
    Ohm's Law - Electricity follows the path of least resistance.

    Regards,

    Mark Norton,

Similar Threads

  1. Changing layer colours in viewports using 2009
    By camilla.mott in forum AutoCAD General
    Replies: 3
    Last Post: 2009-06-30, 02:22 PM
  2. Colours (You cant take Autocad out of the boy)
    By blairmack in forum Revit Architecture - General
    Replies: 13
    Last Post: 2008-05-31, 02:21 AM
  3. Light Colours
    By Jit in forum Revit - Rendering
    Replies: 1
    Last Post: 2005-03-08, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •