CADLisp Tools

Text & Numbering

Sequential Wire Numbering AutoLISP routine

Apply a controlled numeric sequence to selected wire-label text. Download the .LSP source below and run the WIRENO command after loading it.

⌘ WIRENOv0.9.0BeginnerUpdated Sep 16, 2026

What it does

Sequential Wire Numbering with the WIRENO AutoLISP command

A focused electrical drafting helper that numbers existing wire-label TEXT or MTEXT objects one at a time while keeping the drafter in control of the sequence.

AutoLISP command
WIRENO
Difficulty
Beginner

Applicable disciplines

CAD workflows that use this routine

Requirements and compatibility

What it needs

AutoLISP

Software rows marked “Not tested” are not compatibility claims. Test the routine in a copy of your drawing and CAD version.

Downloadable source code

Review the wire-numbering.lsp AutoLISP code

wire-numbering.lspAUTOLISP
;; CADLisp Tools - Sequential Wire Numbering
(defun ct-wn:editable-p (data / flags row)
  (and data
       (setq row (tblsearch "LAYER" (cdr (assoc 8 data))))
       (setq flags (cdr (assoc 70 row)))
       (= 0 (logand flags 20))))

(defun ct-wn:escape-mtext (value / character index output)
  (setq index 1 output "")
  (while (<= index (strlen value))
    (setq character (substr value index 1)
          output (strcat output
                   (if (member character '("\\" "{" "}")) "\\" "")
                   character)
          index (1+ index)))
  output)

(defun ct-wn:text-pairs (value / pairs)
  (setq pairs nil)
  (while (> (strlen value) 250)
    (setq pairs (cons (cons 3 (substr value 1 250)) pairs)
          value (substr value 251)))
  (reverse (cons (cons 1 value) pairs)))

(defun ct-wn:set-value (data value / inserted item new out pair)
  (setq inserted nil new (ct-wn:text-pairs value) out nil)
  (foreach pair data
    (if (member (car pair) '(1 3))
      (if (not inserted)
        (progn
          (foreach item new (setq out (cons item out)))
          (setq inserted T)))
      (setq out (cons pair out))))
  (reverse out))

(defun c:WIRENO (/ *error* count data entity kind number picked prefix skipped undo-started value)
  (defun *error* (message)
    (if undo-started (command-s "_.UNDO" "_End"))
    (if (and message (not (wcmatch (strcase message) "*CANCEL*,*QUIT*,*EXIT*")))
      (prompt (strcat "\nWIRENO error: " message)))
    (princ))
  (setq prefix (getstring T "\nWire prefix (may be blank): ")
        number (getint "\nStarting wire number <1>: "))
  (if (null number) (setq number 1))
  (setq count 0 skipped 0)
  (prompt "\nSelect wire labels in sequence. Press Enter to finish.")
  (if (= 0 (logand 8 (getvar "UNDOCTL")))
    (progn (command "_.UNDO" "_Begin") (setq undo-started T)))
  (while (setq picked (entsel (strcat "\nSelect label for " prefix (itoa number) ": ")))
    (setq entity (car picked) data (and entity (entget entity))
          kind (and data (cdr (assoc 0 data))) value (strcat prefix (itoa number)))
    (if (and (member kind '("TEXT" "MTEXT")) (ct-wn:editable-p data)
             (entmod (ct-wn:set-value data
                       (if (= kind "MTEXT") (ct-wn:escape-mtext value) value))))
      (progn
        (entupd entity)
        (setq number (1+ number) count (1+ count)))
      (progn
        (setq skipped (1+ skipped))
        (prompt "\nSkipped: select editable TEXT or MTEXT on an unlocked, non-xref layer."))))
  (if undo-started (progn (command "_.UNDO" "_End") (setq undo-started nil)))
  (prompt (strcat "\nNumbered " (itoa count) " label(s); skipped " (itoa skipped) "."))
  (princ))

Setup

How to install the wire-numbering.lsp file

  1. 1Save production drawings before testing.
  2. 2Use APPLOAD to load the file.
  3. 3Keep it session-only until reviewed.

Command workflow

How to run the WIRENO command

  1. 1Run WIRENO.
  2. 2Enter an optional prefix.
  3. 3Enter the first number.
  4. 4Pick wire labels in sequence and press Enter.

Worked example

Example: Number four wire labels W-101 through W-104.

  1. Enter W- for the prefix.
  2. Enter 101 for the first number.
  3. Pick four labels in order.
Expected result

The labels read W-101 through W-104.

Read before use

Notes and limitations

  • Does not trace connectivity or validate standards.
  • Replaces the complete selected text value.
  • Not manually tested in a named CAD product/version.

Version history

Changelog

v0.9.0Sep 16, 2026Published as an explicitly untested starter example.

Keep automating

Related tools

Data Extraction4 disciplines

Cable/Route Length

Total selected route polylines and apply an optional allowance percentage.

⌘ CABLELENIntermediateCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Blocks & Attributes4 disciplines

Equipment Tag Numbering

Write a prefix and sequential number into a chosen block attribute.

⌘ EQTAGNOAdvancedCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Text & Numbering6 disciplines

Incremental Text Numbering

Renumber TEXT and MTEXT objects in the exact order you select them.

⌘ NUMTEXTBeginnerCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →