About Setting and Returning System Variables (ActiveX)

The Document object provides the SetVariable and GetVariable methods for setting and retrieving AutoCAD system variables.

For example, to assign an integer to the AutoCAD MAXSORT system variable, use the following code:

AutoLISP
(setq acadObj (vlax-get-acad-object)
      doc (vla-get-ActiveDocument acadObj))
(vla-SetVariable doc "MAXSORT" 100)
Note: The setvar and getvar functions can also be used with AutoLISP. Based on the value returned by system variable, it might be beneficial to use the ActiveX related functions.
VBA (AutoCAD Only)
ThisDrawing.SetVariable "MAXSORT", 100