Select to view content in your preferred language

ArcGIS Script Tool Validation Question

956
3
02-28-2022 02:12 PM
tzz_12
by
New Contributor III

I am creating a ArcGIS script tool. I set a parameter for the output folder pathway and another parameter for the output gdb name. I want to make verify that if the user rerunning the tool and use the same output gdb name, then the tool validation will show a warning message before they press run that states the gdb already exist in their output folder. If they continue, their previous output gdb will be overwritten.  I wrote the script below in the tool validation and received a wrong syntax error when I attempt to open the tool.  I tried to rewrite it two ways and received the same error for both ways. How can I rewrite the validation script to resolve the syntax error? Is there a way to join the two parameters and just create one parameter to allow the user to input the output pathway with their output gdb name? Thanks for your help!

 

def updateMessages(self):
#1st Method
outputGDB = self.params[7] + '/' + self.params[8] +'.gdb'
if self.params[8].value:
workspace = os.path.dirname(outputGDB)
if arcpy.Exists(workspace)
self.params.setErrorMessage = ("The output geodatabase name already exist. Please rename the output geodatabase. Otherwise, it will be overwritten.")

#2nd Method (uncomment the script below)

#outputGDB = self.params[7] + '/' + self.params[8] +'.gdb'
#if self.params[8].value = arcpy.Exists(outputGDB)
     #self.params.setErrorMessage = ("The output geodatabase name already exist. Please rename the output geodatabase. Otherwise, it will be overwritten.")
return

 

 

 

 

 

0 Kudos
3 Replies
HuubZwart
Occasional Contributor

Firstly, you could use a single parameter of type "Workspace" which will ask the user to provide a workspace, but this will limit the option to create a new workspace on the fly. 

Secondly, to access the value of a parameter you need to use self.params[0].value. In addition, you might want to build in checks for empty values, while the user is filling multiple parameters, upon change the validation script will run and may produce errors if not all parameters are filled yet (for example, self.params[7].value + self.params[8].value will produce a TypeError if either is None!)

Thirdly, a few syntax notes:

- that when comparing two values, you need "==" instead of "="

- after an if statement you need ":"

- setErrorMessage is a parameter method, hence the correct syntax would be in the line of:

self.params[0].setErrorMessage("I am an error message")

 

Hope this helps!

0 Kudos
tzz_12
by
New Contributor III

Isn't self.params[0] referring to the first parameter? Or are you just using zero as an example? Thanks!

0 Kudos
HuubZwart
Occasional Contributor
Yes sorry for the confusion, that was an example
0 Kudos