Adding Custom System Variables to AutoCAD

Tuesday, August 26, 2025

This is a feature buried deep in the AutoCAD .NET API documentation: you can create your own system variables.

To do this, you need to modify your registry.

⚠️ A word of caution first — registry modifications always carry risks, so only do this if you're comfortable with this kind of change.

Navigate to the key HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\Rxx.x\ACAD-xxxx\, where Rxx.x is the AutoCAD release and ACAD-xxxx is the product code.

For AutoCAD 2026, for example, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R25.1\ACAD-9101\, because version 2026 corresponds to release 25.1 and the product code is 9101.

The registry key

The value of this key will correspond to your variable's value.

You must also add a DWORD value named PrimaryType with your variable's type. Indeed, the value of a registry key is always of type REG_SZ (a string), but your AutoCAD system variable can have the following types:

  • RTREAL: 5001, a real number such as 2.5
  • RTSHORT: 5003, a 16-bit integer between -32,768 and 32,767
  • RTANG: 5004, a real number
  • RTSTR: 5005, a string
  • RTLONG: 5010, a 32-bit integer between -2,147,483,648 and 2,147,483,647

A quick note about the SZ and DWORD types: these are data types used in programming, particularly in Windows APIs.

SZ stands for String ending with a Zero. To mark the end of the string, a null character (a zero byte) is placed at the end.

DWORD stands for Double WORD. This is because in computing, we have:

  • 1 byte = 8 bits
  • 2 bytes = 16 bits = 1 word
  • 4 bytes = 32 bits = 1 double word
  • 8 bytes = 64 bits = 1 quad word

Make sure to select the decimal base when entering values. By default, regedit uses hexadecimal (base 16), and in that base, 5005 in decimal corresponds to 138d.

You must also specify the storage type with a DWORD value named StorageType:

  • PerSession: 0
  • PerUser: 1
  • PerProfile: 2
  • PerDatabase: 3
  • PerViewport: 4

If you choose 3, for example, the variable will be stored in the DWG (in the AcDbVariableDictionary dictionary).

With 1, it will be stored in the registry, under HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R25.1\ACAD-9101:40C\Variables\MYVAR.

With 2, it will also be stored in the registry, but in the section reserved for the user profile, i.e., HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R25.1\ACAD-9101:40C\Profiles\<Profile Name>\Variables for AutoCAD 2026.

With 0, it will only exist in memory and will be reset on the next AutoCAD startup.

Finally, with 4, it will be specific to each viewport.

There are also other optional values:

  • SecondaryType: None (0), Boolean (1), SymbolName (2), Area (3), Distance (4), Angle (5), UnitlessReal (6) — to specify the variable's usage.
  • TypeFlags: None (0), SpacesAllowed (1), DotMeansEmpty (2), NoUndo (4), Chatty (8), Deprecated (16) — for options that can be combined.
  • Owner: to indicate the name of the application that owns the variable. "exe" is the default value designating the main AutoCAD executable.
  • LowerBound and UpperBound: for numeric values (RTREAL, RTANG, RTSHORT, and RTLONG), these two entries specify the allowed value range.

If you specify an Owner, the variable can only be written by that application. The RIBBONSTATE variable, for example, can only be written by AcWindows.dll because Owner is set to AcWindows.

In .reg format, for a variable named MYVAR of type text with the value FOO, this gives:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R25.1\ACAD-9101\Variables\MYVAR]
@="FOO"
"PrimaryType"=dword:0000138d
"StorageType"=dword:00000003

Once the variable is created, you can use it like any other system variable. For example, I can type MYVAR on the command line to change it, use the AutoLISP functions (getvar) and (setvar), or the .NET methods Application.GetSystemVariable() and Application.SetSystemVariable().


Helping hand Need an AutoCAD (AutoLISP, ObjectARX, .NET, VBA) development? Contact me for a free quote.

On the same topic