Opening the Properties palette or reaching for the ribbon drop-down menu every time you want to switch object colors in AutoCAD gets tiresome fast. When you are editing complex floor plans or mechanical drawings, those extra mouse movements add up and disrupt your focus.
The CEX.lsp (Color Executive) routine simplifies color management down to a single command-line input. It lets you enter a color index number (1 through 255) to immediately update selected objects—or set your active drawing color (CECOLOR) if nothing is selected. Entering 0 instantly resets your selection or active drawing color back to ByLayer.
Key Benefits
Context-Sensitive Switching: Automatically applies the color to selected entities. If no selection is active, it updates your current drawing color for new lines instead.
Instant ByLayer Reset: Enter
0to clear explicit color overrides and revert toByLayerstatus without extra clicks.Zero Ribbon Dependency: Keeps your crosshairs right on your work area without navigating to the top ribbon or side properties panel.
Step-by-Step Guide
Load
CEX.lspin AutoCAD using theAPPLOADcommand.Type
CEXin the command prompt and press Enter.Type an AutoCAD color index number (
1-255) or type0for ByLayer.Select the target objects you want to recolor and hit Enter. (If you press Enter without selecting anything, your default drawing color updates for future objects).
AutoLISP Code (CEX.lsp)
Copy the code below and save it as CEX.lsp inside your AutoCAD support folder:
(defun c:CEX ( / *error* old-cmdecho doc col target-col ss i ent elist )
(vl-load-com)
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(defun *error* (msg)
(if old-cmdecho (setvar "cmdecho" old-cmdecho))
(vla-EndUndoMark doc)
(princ "\nCAD Lisp [www.daolpro.com]")
(princ)
)
(setq old-cmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(vla-StartUndoMark doc)
(setq col (getint "\nEnter color number (0 for ByLayer, 1-255): "))
(if (and col (>= col 0) (<= col 255))
(progn
(if (= col 0)
(setq target-col 256)
(setq target-col col)
)
(setq ss (ssget))
(if ss
(progn
(setq i 0)
(while (setq ent (ssname ss i))
(setq elist (entget ent))
(if (assoc 62 elist)
(setq elist (subst (cons 62 target-col) (assoc 62 elist) elist))
(setq elist (append elist (list (cons 62 target-col))))
)
(entmod elist)
(setq i (1+ i))
)
)
(if (= col 0)
(setvar "cecolor" "BYLAYER")
(setvar "cecolor" (itoa col))
)
)
)
(princ "\nInvalid color number. Please enter between 0 and 255.")
)
(vla-EndUndoMark doc)
(setvar "cmdecho" old-cmdecho)
(princ "\nCAD Lisp [www.daolpro.com]")
(princ)
)
Practical Workflow Tip
When organizing drawing layers, keep most geometry set to ByLayer (Color 0) and use explicit color indexes sparingly for temporary highlights or redlines during revision checks.

Post a Comment