CADLISPMASTER
Stop wasting time on repetitive AutoCAD tasks. CAD LISP Master provides free, efficient AutoLISP codes and clear tutorials designed to automate your workflow and speed up your drafting.

Change Object Color and Current Layer Color Instantly

Boost drafting speed using CEX LISP for quick color changes and ByLayer toggles in AutoCAD.

 [AutoCAD LISP] Change Object Color and Current Layer Color Instantly (CEX.lsp)

Change Object Color and Current Layer Color Instantly
Have you ever felt frustrated by the tedious process of clicking through the properties panel or the color drop-down menu just to change the color of a few lines? AutoCAD’s default interface requires multiple clicks, dragging your mouse away from your workspace, and disrupting your drawing flow.

When working on complex drawings with hundreds of layers, changing colors manually one by one is a massive time-sink. If you don't use a streamlined shortcut for this, you waste valuable minutes every hour just adjusting visual properties. That’s where the CEX (Color Executive) LISP comes in to save your workflow.

Why You Should Use the 'CEX' LISP

  • Zero Workspace Disruption: Change object colors directly from the command line without opening panels.
  • Smart ByLayer Toggle: Simply enter 0 to instantly reset objects or your active color back to ByLayer.
  • Two-in-One Functionality: If objects are selected, it changes their color immediately.
         If no objects are selected, it dynamically changes your current drawing color (CECOLOR).
  • Boosted Drafting Speed: Eliminates repetitive mouse movement, keeping your focus entirely on the design.

How It Works (Step-by-Step Guide)

  1. Load the LISP: Load the CEX.lsp file into AutoCAD using the APPLOAD command.
  2. Run the Command: Type CEX in the command line and press Enter.
  3. Enter Color Number: You will be prompted to enter a color number.
  • Type any index number from 1 to 255 for standard AutoCAD colors.
  • Type 0 to set the target to ByLayer.
  1. Select Objects (Optional):
  • If you select objects: All chosen elements will instantly change to the specified color.
  • If you press Enter without selecting: Your active drawing color changes so that any new lines you draw will automatically have that color.

Wrapping Up

Efficient color management is key to maintaining clean, professional, and readable CAD drawings. The CEX LISP acts as a powerful shortcut that bridges the gap between quick commands and property management. Give it a try, and you’ll notice an immediate reduction in mouse fatigue and drawing time.

If you have any questions or need modifications for this LISP, feel free to leave a comment below!

The LISP Code

(defun c:CEX ( / col ss i ent elist target-col)
  (setvar "cmdecho" 0)
  (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.")
  )
  (setvar "cmdecho" 1)
  (princ)
)

Post a Comment