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.

Add or Remove Thousands Commas Instantly

Efficient AutoCAD LISP (VCC) for formatting numbers. Quickly insert or delete commas in text selection.

 [AutoCAD LISP] Add or Remove Thousands Commas Instantly (VCC.lsp)

Add or Remove Thousands Commas Instantly
When working on architectural or engineering drawings in AutoCAD, dealing with large numbers, cost estimates, or dimension tables is inevitable. Manually typing in thousands separators (commas) for dozens of text objects is not only incredibly tedious but also opens the door to human error. Conversely, trying to extract or calculate raw numeric data from text that already contains commas can break your workflow.

Without this LISP, you are stuck double-clicking every single Text or MText entity, moving your cursor, and typing or deleting commas one by one. It slows down your drafting speed and drains your energy.

This is where the VCC (Value Comma Change) LISP comes in. It allows you to select multiple numbers at once and instantly add or remove thousands separators with just a few clicks.

Why You Should Use the 'VCC' LISP

  • Effortless Batch Processing: Format hundreds of text items simultaneously instead of editing them one by one.
  • Dual Functionality: Easily switch between adding commas (1234567 → 1,234,567) and removing commas (1,234,567 → 1234567).
  • Smart Decimal Support: The LISP intelligently detects decimal points and only formats the whole number part, preventing any data corruption.
  • Text & MText Compatibility: Works seamlessly with both standard Text and multi-line MText objects.

How It Works (Step-by-Step Guide)

  1. Load the LISP File: Type APPLOAD in the AutoCAD command line, select the VCC.lsp file, and click 'Load'.
  2. Run the Command: Type VCC in the command line and press Enter.
  3. Select Objects: Select the Text or MText objects you want to modify, then press Enter.
  4. Choose Your Option: Type A (or press Enter) for Add to insert thousands commas.
  • Type R for Remove to delete existing commas.
  1. Instant Result: Watch your selected numbers format automatically in the blink of an eye.

Wrapping Up

Please click the button below to download the LISP file. If you encounter any bugs or have feature requests, feel free to leave a comment below!

The LISP Code


  (vl-load-com)
(defun c:VCC (/ ss mode i sn elist is-m obj txt num res dec len c str)
  (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
    (progn
      (initget "Add Remove")
      (if (not (setq mode (getkword "\nChoose option [Add(A)/Remove(R)] : ")))
        (setq mode "Add")
      )
      (setq i 0)
      (repeat (sslength ss)
        (setq sn (ssname ss i) elist (entget sn) is-m (= (cdr (assoc 0 elist)) "MTEXT"))
        (if is-m
          (setq obj (vlax-ename->vla-object sn) txt (vla-get-textstring obj))
          (setq txt (cdr (assoc 1 elist)))
        )
        (cond
          ((= mode "Remove")
            (setq res "" len (strlen txt) c 1)
            (while (<= c len)
              (if (/= (setq str (substr txt c 1)) ",") (setq res (strcat res str)))
              (setq c (1+ c))
            )
            (if is-m (vla-put-textstring obj res) (entmod (subst (cons 1 res) (assoc 1 elist) elist)))
          )
          ((= mode "Add")
            (setq num (vl-string-translate "," "" txt))
            (if (not (vl-catch-all-error-p (vl-catch-all-apply 'distof (list num))))
              (progn
                (setq res "" dec "")
                (if (vl-string-search "." num)
                  (setq dec (substr num (1+ (vl-string-search "." num)))
                        num (substr num 1 (vl-string-search "." num)))
                )
                (setq len (strlen num))
                (while (> len 3)
                  (setq res (strcat "," (substr num (- len 2) 3) res)
                        num (substr num 1 (- len 3))
                        len (strlen num))
                )
                (setq res (strcat num res))
                (if (/= dec "") (setq res (strcat res "." dec)))
                (if is-m (vla-put-textstring obj res) (entmod (subst (cons 1 res) (assoc 1 elist) elist)))
              )
            )
          )
        )
        (setq i (1+ i))
      )
    )
    (prompt "\nNo TEXT or MTEXT entities selected.")
  )
  (princ)
)

Post a Comment