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.

Batch Swap AutoCAD Blocks Instantly: Replace Multiple Entities with Master Block

Batch replace and swap multiple block entities in AutoCAD with a master block using CBS.lsp. Retain target coordinates, scale, and rotation angles.
Replace and Swap Multiple Blocks Instantly

During design revisions on architectural floor plans, site layouts, or electrical schedules, swapping out block symbols happens constantly—whether replacing light fixture types, updating furniture families, or changing landscape symbols. Doing this manually means deleting old blocks and reinserting new ones at every coordinate, or risking scale and rotation misalignments with complex block redefinition workarounds.

The CBS.lsp (Change Block Select) routine reduces block replacement to a simple pick-and-select workflow. You select your source "master" block, then select any group of target blocks across your drawing. The script instantly updates the block definition while maintaining each target block's original coordinates, scale factors, and rotation angles.


Key Workflow Advantages

  • Visual Master Selection: Click directly on your new replacement block on screen—no need to search through nested design center menus or retype block names.

  • Flexible Batch Selection: Select target blocks individually or drag a wide crossing window over entire room layouts to replace dozens of blocks in one pass.

  • Preserved Placement Properties: Updates the block definition while keeping target insertion points, scaling, and rotation angles intact.


How to Execute CBS.lsp

  1. Load CBS.lsp into your AutoCAD session using the APPLOAD command.

  2. Type CBS in the command prompt and press Enter.

  3. Click on the master block (the new block model you want to use as your source).

  4. Select or drag a selection window over all the target blocks you want to replace.

  5. Press Enter to confirm. The command line displays the total count of successfully swapped blocks.


AutoLISP Code (CBS.lsp)

Copy the code below and save it as CBS.lsp inside your AutoCAD support folder:

(defun c:CBS ( / *error* oldCmd oldOsm masterBlk masterName ss i ent obj )
  (vl-load-com)
  (setq oldCmd (getvar "CMDECHO")
        oldOsm (getvar "OSMODE"))
  (setvar "CMDECHO" 0)
  (command-s "_.UNDO" "_BE")
  
  (defun *error* (msg)
    (if oldOsm (setvar "OSMODE" oldOsm))
    (if oldCmd (setvar "CMDECHO" oldCmd))
    (command-s "_.UNDO" "_E")
    (princ "\nCAD Lisp [www.daolpro.com]")
    (princ)
  )

  (if (and (setq masterBlk (car (entsel "\nSelect the master block (new): ")))
           (= (cdr (assoc 0 (entget masterBlk))) "INSERT"))
    (progn
      (setq masterName (vla-get-name (vlax-ename->vla-object masterBlk)))
      (princ "\nSelect or drag target blocks to be replaced: ")
      (if (setq ss (ssget '((0 . "INSERT"))))
        (progn
          (setq i 0)
          (repeat (sslength ss)
            (setq ent (ssname ss i)
                  obj (vlax-ename->vla-object ent))
            (if (vlax-write-enabled-p obj)
              (vla-put-name obj masterName)
            )
            (setq i (1+ i))
          )
          (princ (strcat "\nSuccessfully replaced " (itoa (sslength ss)) " block(s)."))
        )
        (princ "\nNo target blocks selected.")
      )
    )
    (princ "\nInvalid selection. Master must be a block.")
  )

  (if oldOsm (setvar "OSMODE" oldOsm))
  (if oldCmd (setvar "CMDECHO" oldCmd))
  (command-s "_.UNDO" "_E")
  (princ "\nCAD Lisp [www.daolpro.com]")
  (princ)
)

Practical Layout Tip

Place your new master block in a dedicated legend box outside the printable sheet area before running CBS so you can easily select it as a reference without picking from crowded floor plan geometry.

Post a Comment