I'm just getting started with Python toolboxes in ArcGIS and I'm pretty new to Python in general. I've created a python toolbox which
- takes an raster input file
- derives some values based on the name of the input file (via a custom function)
- suggests several parameter values
- processes the files in some way (not relevant to my question)
My issue is, that I cant seem to override the suggested parameter values when I run the tool. The values always switch back to the original values as suggested via the custom function. My guess is that whenever I change the suggested parameter, the function updateParameters() is run which in turn overrides my manual input. Is there a way to solve this dilemma?
I've reduced my toolbox (.pyt-File) to a minimal example (excluding the geoprocessing part) in the following code. In this example, the function
suggestName() returns a new filename with the ending ".shp" and a path to the scratch folder. Imagine the function
suggestName() to be slightly more complex and returning several values, not just one.
import arcpy def suggestName(inputname): "Extract the Sheetnumber and Year from a given map Name" return inputname+".shp" class Toolbox(object): def __init__(self): """Toolbox""" self.label = "Toolbox" self.alias = "Toolbox" # List of tool classes associated with this toolbox self.tools = [Tool] class Tool(object): def __init__(self): """Some Info""" self.label = "Tool" self.description = "Tool" self.canRunInBackground = False def getParameterInfo(self): """""" ## Raster map to extract features from param0 = arcpy.Parameter( name = "inputRaster", displayName = "Inpurt Raster File (TA25)", parameterType = "Required", direction = "Input", datatype = "DERasterDataset" ) ## Output feature class param1 = arcpy.Parameter( displayName="Output Features", name="out_features", datatype="GPFeatureLayer", parameterType="Requred", direction="Output") return [param0,param1] def updateParameters(self, parameters): """""" if parameters.value: parameters.enabled = True newname = suggestName(arcpy.Describe(parameters.valueAsText).basename) parameters.value = newname return def execute(self, parameters, messages): """""" return
It seems like I wasn't very clear in clarifying my issue, I'll try to do so now. As you can see in the screenshot below, the tool suggests the name "test.shp" as the output file. But I cannot override this parameter. If I try to do so (e.g. change the name to "test_2.shp") the parameter switches back to the original name ("test.shp") once I click anywhere outside the box.