How To: Use the RegisterEnvVar request to save environment variables in .apr files


How do I use the RegisterEnvVar request to enable Arcview to save environment variables in a project file?


The Arcview 3.2 online help describes how to use the new request RegisterEnvVar in the What's New in Arcview 3.2 section, but it leaves out one important factor. Here's what it states:

ArcView GIS can now maintain environment variable settings when project files are saved to disk. You can now register a set of environment variables with ArcView GIS. When project files are saved and path names match the registered environment variables, the path is saved using the variable instead of the full path name. Two new Avenue requests have been added to support this:

System.RegisterEnvVar(envVar, path)


Additionally, ArcView GIS initialization has been modified to look for and run a script file named "avenv.ave" when the application starts. This allows for a set of environment variables to be registered with ArcView GIS before any projects are loaded. ArcView GIS will look for this script under $AVHOME/etc, $HOME and $TEMP and, if present, will run the script from each location. You can create an "avenv.ave" file in any of these locations and write the System.RegisterEnvVar request for each of the variables you want to register. Here is an example of what this file could look like:

System.RegisterEnvVar("MyData", "c:\data")

System.RegisterEnvVar("CityData", "d:\city\data")

If you have the registered environment variables set on your system, you can then open projects containing paths with variables without error. Use the System.UnregisterEnvVar to unregister the variables so that project files will be saved with full, expanded path names.


What the online help fails to mention is the fact that this request will only work when used in a project that exists on the harddrive. The request will not do anything if you try using it before the project is saved to the harddrive. Once the project is saved to the hard drive, the request should work OK.

Similarly, using the avenv.ave functionality will not do anything if you are opening a new project. It will only work if you are opening a project that already exists on the harddrive.
If you run the request from the script editor multiple times in an existing project, then the variable name will start duplicating itself in the project file, making the pathnames invalid.