Use System Variables and Settings Safely

Level

Requirement

Applies to

ObjectARX and .NET applications

If a function is not supposed to change any AutoCAD system variables explicitly, but needs to change them for the duration of its execution, it should restore the original values before returning control to the caller.

You must carefully evaluate when to restore system variables. For example, a call to an application's functions from within another function may require the original variable settings. Exception handlers, too, must restore the original system variable values, because control passes back to AutoCAD if your application shuts down unexpectedly.

A recommended method is to save the values of such system variables in temporary copies, and then restore those values when appropriate. If users directly modify a system variable setting after the application saves its state, they will lose the value they set when the application restores the "old" value.

A list of system variables is available in the AutoCAD product Help files. USER variables are for use by users. Applications may need to use USER variables for tasks such as DIESEL communication. USER variables should be saved and restored after each command so that their use is transparent to the user.

It's important to know whether each system variable is instantiated separately for each document or whether one variable is applicable across all open documents.