Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to change system variable?
Message
Information générale
Forum:
CAD
Catégorie:
Autocad Lisp
Divers
Thread ID:
00411664
Message ID:
00411785
Vues:
9
>How can I change system variable from a lisp program?
>For exemple I like to the the _FILEDIA system variable.

(setvar "SomeSysVar" SomeValue) ; Sets the var
(getvar "SomeSysVar") ; returns the current value

:)

Below are a couple functions I use to both store and restore any sysvars that a program may change.

At the beginning of a function you would call SysVarStore like this:
(SysVarStore
    '("CMDECHO"     "BLIPMODE"	   "MENUECHO"	 "CECOLOR"
      "CLAYER"	     "HIGHLIGHT"   "LIMCHECK"	 "CMDDIA"
      "FILEDIA"     "ATTDIA"	   "REGENMODE"	 "LUNITS"
      "LUPREC"
     )
) ;_ end of SysVarStore
and each of the sysvars in the list has it's value captured. Then at the end of the function you would call SysVarReset to restore thier original values. It works by creating a global var of a list that contains each sysvar and it's current value.
;;;==================================================================
;;;  (SysVarStore v)
;;;		Store system variables
;;;------------------------------------------------------------------
;;; Parameters:
;;;		v	list of var names to store ("CMDECHO" "CLAYER")
;;;------------------------------------------------------------------
;;;	Returns:
;;;		sets global var Lobot:SVARS
;;;------------------------------------------------------------------
(defun SysVarStore (v)
	(setq Lobot:SVARS '())
	(repeat	(length v)
		(setq Lobot:SVARS
				 (cons (list (car v) (getvar (car v)))
					   Lobot:SVARS
				 ) ;_ end of cons
		) ;_ end of setq
		(setq v (cdr v))
	) ;_ end of repeat	
) ;_ end of defun
;;;==================================================================
;;;  (SysVarReset)
;;;		Reset system vars changed by SysVarStore
;;;------------------------------------------------------------------
;;; Parameters:
;;;		uses global var Lobot:SVARS
;;;------------------------------------------------------------------
;;;	Returns:
;;;		always returns nil
;;;------------------------------------------------------------------
(defun SysVarReset ()
	(if	Lobot:SVARS
		(progn
			(repeat	(length Lobot:SVARS)
				(setvar (caar Lobot:SVARS) (cadar Lobot:SVARS))
				(setq Lobot:SVARS (cdr Lobot:SVARS))
			) ;_ end of repeat
			(setq Lobot:SVARS nil)
		) ;_ end of progn
	) ;_ end of if
) ;_ end of defun
Roi
'MCP' Visual FoxPro

In Rome, there was a poem.
About a dog, who found two bone.
He lick the one, he lick the other.
He went pyscho, he drop dead!
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform