Default arcpy.GetParameterAsText(0)

1824
3
Jump to solution
11-15-2016 05:18 PM
jaykapalczynski
Frequent Contributor

Is there a way to default Get parametersAsTest

Where when I run the tool it will be defaulted unless the user changes it.

def main():
sde_conn = arcpy.GetParameterAsText(0) or "C:\Users\xx\AppData\Roaming\ESRI\Desktop10.4\ArcCatalog\x@x.sde"
0 Kudos
1 Solution

Accepted Solutions
RebeccaStrauch__GISP
MVP Emeritus

Are you creating a tool in a toolbox for your user input?  If so, you you set up you default int he Parmaters box, for example:

Then in the script, you could have something like this:

# Script arguments...
targetGDB = arcpy.GetParameterAsText(0)
if not targetGDB:
  targetGDB = r'\\DFGANCGISDEV3\agsdev\data\update.gdb' ‍‍‍‍

Simple sample, but then you repeat for the other parameters. 

edit: by the way, I should mention that they will see the default you have in the Parameter box, but can change it.   The "if not" covers if nothing is input....at least you ahve the default, for example if you didn't have a default in the Parameter box, and they left the input blank, you could still have the default.

View solution in original post

3 Replies
DanPatterson_Retired
MVP Emeritus

are you looking to set parameters? this is one, there are other options in the same help file vacinity

SetParameterAsText—Help | ArcGIS for Desktop 

jaykapalczynski
Frequent Contributor

Got it with this:  ArcGIS Help 10.1 

Was able to set the default when I was setting parameters.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Are you creating a tool in a toolbox for your user input?  If so, you you set up you default int he Parmaters box, for example:

Then in the script, you could have something like this:

# Script arguments...
targetGDB = arcpy.GetParameterAsText(0)
if not targetGDB:
  targetGDB = r'\\DFGANCGISDEV3\agsdev\data\update.gdb' ‍‍‍‍

Simple sample, but then you repeat for the other parameters. 

edit: by the way, I should mention that they will see the default you have in the Parameter box, but can change it.   The "if not" covers if nothing is input....at least you ahve the default, for example if you didn't have a default in the Parameter box, and they left the input blank, you could still have the default.