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!
outputGDB = self.params + '/' + self.params +'.gdb'
workspace = os.path.dirname(outputGDB)
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 + '/' + self.params +'.gdb'
#if self.params.value = arcpy.Exists(outputGDB)
#self.params.setErrorMessage = ("The output geodatabase name already exist. Please rename the output geodatabase. Otherwise, it will be overwritten.")
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.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.value + self.params.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.setErrorMessage("I am an error message")
Hope this helps!
Isn't self.params referring to the first parameter? Or are you just using zero as an example? Thanks!