Usage of environment variables (e.g. %TEMP%) in values of tool parameters

702
4
03-15-2023 01:19 PM
Status: Open
Labels (1)
ChristophKoschmieder
New Contributor III

In order to provide dynamic values for tool parameters, it would be very useful to support the use of environment variables (e.g. %TEMP%, %USERPROFILE%, %APPDATA%, or any other custom environment variables) in values of tool parameters.

4 Comments
JonathanNeal

@ChristophKoschmieder Are you thinking of a programatic way to use these locations that are shown in the Browse Dialog?

JonathanNeal_0-1678987618159.png

 

ChristophKoschmieder

Hi @JonathanNeal, no, my idea targets a more general use of *any* (windows / operation system) environment variable in parameter values for geoprocessing tools.

Let's say you develop a python geoprocessing tool, which has a parameter to hold the user currently logged in, then I would like to do the following:

param = arcpy.Parameter("usr", "Logged in User", "Input", "GPString", "Required")

param.value = "%USERNAME%"

And when executing the tool the value above is dynamically replaced by the current value of the environment variable.

We need this functionality especially, because right now we are migrating a project from ArcGIS desktop and WMX to ArcGIS Pro. Because the full functionality of WMX is no longer needed, we are planning without it in ArcGIS Pro, but we would like to keep the possibility to have dynamic parameter values.

JonathanNeal

@ChristophKoschmieder Per the similar case in the ModelBuilder thread you can do the following:

param = arcpy.Parameter("usr", "Logged in User", "Input", "GPString", "Required")

param.value = arcpy.GetSystemEnvironment("USERNAME")

 

ChristophKoschmieder

Hi @JonathanNeal,

you are right for the parameter initialization, but we would like to enable the _user_ to use environment variables as parameter values _after_ opening the tool dialog (thus changing the default value).