CADLisp Tools

Dimensions & Annotation

Room Area Label AutoLISP routine

Place a room-area text label from a selected closed polyline. Download the .LSP source below and run the ROOMAREA command after loading it.

⌘ ROOMAREAv1.0.0IntermediateUpdated Sep 18, 2026

What it does

Room Area Label with the ROOMAREA AutoLISP command

Reads one room boundary, asks for a room name and insertion point, and creates a two-line MTEXT label with raw drawing-unit area.

AutoLISP command
ROOMAREA
Difficulty
Intermediate

Applicable disciplines

CAD workflows that use this routine

Requirements and compatibility

What it needs

AutoLISPVisual LISPActiveX

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 room-area-label.lsp AutoLISP code

room-area-label.lspAUTOLISP
;; CADLisp Tools - Room Area Label
(vl-load-com)

(defun ct-ra:current-layer-writable-p (/ row flags color)
  (and (setq row (tblsearch "LAYER" (getvar "CLAYER")))
       (setq flags (cdr (assoc 70 row)) color (cdr (assoc 62 row)))
       (= 0 (logand flags 21))
       (>= color 0)))

(defun ct-ra:2d-polyline-p (data / flags)
  (and data
       (or (= (cdr (assoc 0 data)) "LWPOLYLINE")
           (and (= (cdr (assoc 0 data)) "POLYLINE")
                (setq flags (cdr (assoc 70 data)))
                (= 0 (logand flags 88))))))

(defun ct-ra:replace-all (text find replacement / position start)
  (setq start 0)
  (while (setq position (vl-string-search find text start))
    (setq text (strcat (substr text 1 position) replacement
                       (substr text (+ position (strlen find) 1)))
          start (+ position (strlen replacement))))
  text)

(defun ct-ra:escape-mtext (value)
  (setq value (ct-ra:replace-all value "\\" "\\\\")
        value (ct-ra:replace-all value "{" "\\{")
        value (ct-ra:replace-all value "}" "\\}"))
  value)

(defun ct-ra:make-mtext (point value / normal ucs-x)
  (setq normal (trans '(0.0 0.0 1.0) 1 0 T)
        ucs-x (trans '(1.0 0.0 0.0) 1 0 T))
  (entmakex
    (list '(0 . "MTEXT") (cons 8 (getvar "CLAYER"))
          (cons 10 point) (cons 40 (getvar "TEXTSIZE"))
          (cons 1 value) (cons 7 (getvar "TEXTSTYLE"))
          '(71 . 5) (cons 11 ucs-x) (cons 210 normal))))

(defun c:ROOMAREA (/ *error* area closed data ent name obj pick point result undo-started)
  (defun *error* (message)
    (if undo-started (command-s "_.UNDO" "_End"))
    (if (and message (not (wcmatch (strcase message) "*CANCEL*,*QUIT*,*EXIT*")))
      (prompt (strcat "\nROOMAREA error: " message)))
    (princ))
  (cond
    ((not (ct-ra:current-layer-writable-p))
      (prompt "\nThe current layer is off, frozen, locked, or xref-dependent; no label created."))
    ((null (setq pick (entsel "\nPick a closed room polyline: ")))
      (prompt "\nNo boundary selected."))
    ((not (ct-ra:2d-polyline-p (setq data (entget (setq ent (car pick))))))
      (prompt "\nThe selected object is not a supported 2D polyline."))
    ((or (vl-catch-all-error-p
           (setq closed (vl-catch-all-apply 'vlax-curve-isClosed (list ent))))
         (not closed))
      (prompt "\nThe selected boundary is open or invalid."))
    ((= (setq name (getstring T "\nRoom name: ")) "")
      (prompt "\nRoom name cannot be blank."))
    ((vl-catch-all-error-p
       (setq obj (vl-catch-all-apply 'vlax-ename->vla-object (list ent))))
      (prompt "\nThe selected boundary cannot be accessed through ActiveX."))
    ((vl-catch-all-error-p
       (setq result (vl-catch-all-apply 'vla-get-Area (list obj))))
      (prompt "\nThe selected boundary has no valid calculable area."))
    ((null (setq point (getpoint "\nLabel insertion point: ")))
      (prompt "\nNo insertion point supplied."))
    (T
      (setq area result point (trans point 1 0))
      (if (= 0 (logand 8 (getvar "UNDOCTL")))
        (progn (command "_.UNDO" "_Begin") (setq undo-started T)))
      (if (ct-ra:make-mtext point
            (strcat (ct-ra:escape-mtext name) "\\PAREA=" (rtos area 2 2)))
        (prompt "\nRoom area label created.")
        (prompt "\nThe room area label could not be created."))
      (if undo-started (progn (command "_.UNDO" "_End") (setq undo-started nil)))))
  (princ))

Setup

How to install the room-area-label.lsp file

  1. 1Download and review the source code.
  2. 2Load the .lsp file with APPLOAD in a copy of a drawing.
  3. 3Keep the routine session-only until it has been tested for your CAD version and standards.

Command workflow

How to run the ROOMAREA command

  1. 1Run ROOMAREA.
  2. 2Pick a closed room boundary.
  3. 3Enter the room name and place the label.

Worked example

Example: Label a conference room boundary.

  1. Run ROOMAREA.
  2. Pick the boundary.
  3. Enter Conference and place the label.
Expected result

MTEXT shows the room name and area.

Read before use

Notes and limitations

  • Area is not unit-converted and the label is not associative.
  • Uses current layer and text style.
  • Not manually CAD-tested.

Version history

Changelog

v1.0.0Sep 18, 2026Initial room name and area label routine.

Keep automating

Related tools

Dimensions & Annotation5 disciplines

Area Label

Place a text label containing a selected closed polyline's area.

⌘ AREALABELIntermediateCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Geometry & Polylines6 disciplines

Closed Polyline Area

Sum the area of selected closed polylines and skip open ones.

⌘ CLOSEDARIntermediateCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Dimensions & Annotation6 disciplines

Coordinate Label X/Y

Create a WCS X/Y text label at a picked coordinate.

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