The Document object provides the SetVariable and GetVariable methods for setting and retrieving AutoCAD system variables. For example, to assign an integer to the MAXSORT system variable, use the following code:
ThisDrawing.SetVariable "MAXSORT", 100