Hi,
To set and restore system variables, you can also the ai_sysvar function.
This function is available in AutoCAD since a while.
It's defined in acaddoc20XX.lsp (ai_utils.lsp or acad.mnl in older versions), so it's automatically loaded in each document.
;;; --- ai_sysvar ------------------------------------------
;;; Change system variable settings and save current settings
;;; (Note: used by *merr* to restore system settings on error.)
;;;
;;; The <vars> argument is used to...
;;; restore previous settings (ai_sysvar NIL)
;;; set a single sys'var (ai_sysvar '("cmdecho" . 0))
;;; set multiple sys'vars (ai_sysvar '(("cmdecho" . 0)("gridmode" . 0)))
;;;
;;; defun-q is needed by Visual Lisp for functions which redefine themselves.
;;; it is aliased to defun for seamless use with AutoLISP.
Anywhere in the code, you can call ai_sysvar to save the current value of one or more sysvar and set it a new value (or not).
Example:
;; save and set "osmode" to 0
(ai_sysvar '("osmode" . 0))
...
;; save and set "orthomode" to 1 and only save "autosnap"
(ai_sysvar '(("orthomode" . 1) ("autosnap" . nil)))
...
;; restor all sysvars
(ai_sysvar nil)
<EDIT> I forgot to say, the implementation of ai_sysvar is quite interesting with the use of defun-q which allows to store the list of var names ans values within the function.