Function Entry: SETVAR

← Prev | ↑ Chapter | Next → | Index | Symbols

Function Entry: SETVAR

Name

setvar

Class

Host Interaction Function

Syntax

(setvar varname value)

Arguments and Values

  • varname: system-variable name designator
  • value: new value

Autodesk documents:

  • varname as a string
  • value as an integer, real, string, list, T, or nil

Description

Sets an AutoCAD system variable to a specified value.

The per-sysvar entries in §16 System Variables document every varname recognized by AutoCAD 2026 or BricsCAD V25, with the declared type, default, read-only flag, scope, accepted-value range, vendor divergence, and source URLs. The normative rules at the head of that chapter (name case-insensitivity, integer clamping to [-32768, +32767], type-coercion policy, read-only error behaviour, angular-units convention for ANGBASE / SNAPANG) apply uniformly to every setvar call.

Return Values

Returns value if successful.

Side Effects

Mutates host drawing/session state.

Exceptional Situations

Errors if the variable is read-only, absent, or rejects the supplied value.

Availability

  • AutoCAD 2026: documented (per Autodesk reference page).
  • BricsCAD V26: presumed compatible (no contradicting page found).
  • Status: AutoCAD documented; BricsCAD presumed-both pending Phase 4 verification.

Source Notes

Notes

  • Autodesk documents that for integer-valued system variables the supplied value must lie between -32768 and +32767.
  • Autodesk documents that changes made with setvar during an active command may not take effect until the next command.
  • Autodesk documents special angular semantics for ANGBASE and SNAPANG: setvar interprets the values in radians, unlike the interactive SETVAR command.

Compatibility

Supported on Windows, macOS, and Web in current Autodesk documentation.

Tested Behaviour (sunset campaign B4, 2026-10-28)

probe-setvar-edges.lsp; AutoCAD 2022 job 17540963671, BricsCAD V25 Windows 17540963675, BricsCAD V26 macOS 17540963672. (RESULT AFTER ERRNO) per case:

case AutoCAD 2022 BricsCAD V25 / V26
out of the variable's range error, unchanged, ERRNO 22 error, unchanged, ERRNO 0
(CMDECHO 2, LUNITS 7, OSMODE -1)    
OSMODE 70000, USERI1 40000 error, ERRNO 22 wrapped to 16 bits (4464, -25536)
CMDECHO 1.0 returns 1.0, stores 1 the same
CMDECHO 0.7 error, ERRNO 87 stores 0
a string / nil for a number error, ERRNO 87 "bad argument type", ERRNO 0
an integer for a real (USERR1 2) returns 2, stores 2.0 the same
SNAPBASE (a 2D point) '(1 2 3) error stores (1.0 2.0)
read-only (DWGNAME, ACADVER) error, ERRNO 20 error, ERRNO 20
ERRNO (documented read-only) accepted, ERRNO = the value accepted, ERRNO = the value
unknown name error, ERRNO 0 error, ERRNO 0
(setvar 'OSMODE 1), a symbol name accepted accepted
"osmode", "OsMode" accepted accepted
ANGBASE / SNAPANG under AUNITS 0, 3 radians, AUNITS ignored the same

SETVAR returns the value it was GIVEN, not the one it stored.

The ERRNO row comes from the error-processing catalogue (probes/error-processing/, 2026-11-03), which resets ERRNO with (setvar "ERRNO" 0) before each of its cases on AutoCAD 2022 (accoreconsole), BricsCAD V25 (Windows) and BricsCAD V26 (macOS).

clautolisp: SETVAR

Not yet as measured: no range check, ERRNO 1 for a read-only or unknown name and 4 for a bad type, the stored value returned, a symbol name refused: issues/open/setvar-validation-as-measured.issue.