• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
blog.draftsperson.net

blog.draftsperson.net

the art of technical drawing

blog.draftsperson.net

Block to BYLAYER LISP: Reset Block Colours in AutoCAD

September 18, 2020

Last updated July 28, 2026

This resets the contents of your block definitions to BYLAYER, so blocks stop carrying hard-coded colours and start taking their appearance from the layer you insert them on. It is the fix for a drawing where every symbol comes in red no matter what layer it lands on.

Sensibly, it skips xrefs and xref-dependent blocks. Those belong to another drawing and editing their definitions in yours would achieve nothing useful.

There is no command to type

Deal with this first, because it is the whole difficulty with the download.

An AutoLISP file makes something available as a typed command by defining it with a C: prefix on the name. This file does not do that anywhere. It defines its work as an ordinary function called LAYERFIX, which means loading the file gives you nothing at the command line — type LAYERFIX and AutoCAD will tell you it is an unknown command.

What you have to do instead is call it as a function, by typing it with brackets around it:

(layerfix)

That works and is how the author presumably used it — probably called from another routine or a menu macro rather than typed. If you would rather have a proper command, add one line to the end of the file:

(defun c:layerfix () (layerfix))

The file’s own header calls it Layerfix.LSP, while the download is named after the BYLAYER job it does — so the two names you might expect to type are both wrong, and the real answer is the third one.

Why BYLAYER matters

Worth stating for anyone who has inherited a drawing and not met this problem before.

When a block is built, the objects inside it can either carry their own explicit colour or be set to BYLAYER. If they carry their own, the block looks the same wherever you put it — which sounds convenient and is the opposite of what you want, because it means your layer scheme has no effect on it. Plot styles keyed to colour stop working, layer-based control stops working, and turning something a different colour means editing every block.

Setting the contents to BYLAYER hands control back to the layer. Insert the block on a layer and it looks like that layer. That is how a block library should behave.

Note that this changes the block definitions, so every insertion of an affected block changes at once. That is the point, and it is also the reason to work on a copy.

How to load it

Unzip Bylaybk.zip and load the .lsp file with APPLOAD, then call it as described above. No support files. Our AutoLISP guide covers loading.

Step-by-step usage

  1. Work on a copy. This edits block definitions and affects every insertion.
  2. Load the file with APPLOAD.
  3. Type (layerfix) at the command line, brackets included, or add the wrapper line above and type LAYERFIX.
  4. Regenerate, then check a few blocks on different layers to confirm they now follow the layer colour.

If a block still comes in with its own colour after running this, check whether it is an xref-dependent block — those are deliberately skipped.

Compatibility notes

No date or author in the file. It works by walking block definitions and editing entity data directly, which is the durable approach and has not changed.

Plain AutoLISP with no dialog boxes and no Express Tools calls, so nothing requires the full product; LT users on LT 2024 or later, the release that brought AutoLISP to LT, should be able to run it. See what runs on AutoCAD LT.

If you want the same job with a proper command and a choice of colour, UPDBLOCK does it as two commands you can type.

Download

Name: Block to Bylayer
Description: Changes the block definitions to BYLAYER .
Will skip all XREF & XREF dependent blocks.
Type: AutoCAD AutoLISP Routine
Author: Anon
File Size: 2 Kb
Cost: Free
Worked on: AutoCAD
Download File: Bylaybk.zip

Related routines

  • UPDBLOCK — the same job as two typed commands, layer and colour separately.
  • Fixblock — another block maintenance routine.
  • Block Count Report — find out what blocks you have before fixing them.

References

  • AutoLISP: the complete guide
  • Free LISP routines library
  • AutoLISP Lesson 4: Program Format
  • AutoLISP on AutoCAD LT

Filed Under: AutoLISP Routines

Primary Sidebar

Subscribe to our Youtube Channel

Post CAD drafting jobs on Freelancer.com. and get some free money to do this.

Categories

  • American Steel Industry (4)
  • AutoCAD Articles & Reference (30)
  • AutoCAD Bugs & Problems (19)
  • AutoCAD Tips (29)
  • AutoCAD Tutorials (54)
  • AutoLISP Routines (328)
  • AutoLISP Tutorials (15)
  • CAD Standards (7)
  • Civil 3D (7)
  • Civil Drafting (4)
  • Dimensions (2)
  • Drafting Funnies (71)
  • Drafting History (9)
  • Drafting Standards (84)
  • Electrical Drafting (2)
  • General IT reference (7)
  • Geometry (15)
  • GIS (2)
  • Hatch Patterns (12)
  • Office Life Hacks (3)
  • PT (1)
  • Revit Tutorials (54)
  • Steel Detailing (14)
  • Structural Drafting (26)
  • Technical Dictionary (61)
  • Useful Website Links (19)

Footer

Free downloads

  • Free AutoLISP routines
  • Free hatch patterns
  • SHX fonts & text styles
  • Numbering LISP collection
  • ISO 3098B font

Reference charts

  • AWS weld symbols chart
  • Steel detailing chart
  • Hole & slot sizes
  • Bolt edge distance
  • ANSI & ARCH paper sizes
  • How to fold an A1 drawing

Useful links

  • CAD blocks (DWG)
  • Revit families
  • structuraldrafter.com
  • cad-corner.com
  • About
  • Privacy policy

Provided for free with no warranty · Log in