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:
(setq acadObj (vlax-get-acad-object) doc (vla-get-ActiveDocument acadObj)) (vla-SetVariable doc "MAXSORT" 100)
ThisDrawing.SetVariable "MAXSORT", 100