I am writing a Python Toolbox which needs Shapefiles (or Featureclasses) as input and calculates an output for each of the input files. I would like to have the possibility to rename the files in order to avoid an overwriting or an exception. My approach is to use a toolbox parameter of type GPValueTable with 2 columns. The input files is given in the first column (by the user) and I want the 2. column to be automatically filled by the base name without extension of the input file.
Unfortunatelly, I am not able to fill the second column based on the first. I tried various ways already but here is a snipped of sample code:
def getParameterInfo(self):
"""Define parameter definitions"""
input_paths = arcpy.Parameter(
displayName="Input files",
name="in_paths",
datatype="GPValueTable",
parameterType="Required",
direction="Input",
multiValue=True)
input_paths.columns = [['GPFeatureLayer','Eingabedatensatz'], ['GPString','Ausgabename']]
output_path = arcpy.Parameter(
displayName="Output path",
name="out_path",
datatype="DEFolder",
parameterType="Required",
direction="Input")
params = [input_paths,output_path]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
if parameters[0].value:
new_vt = []
gp_value_table = parameters[0].value
vt_length = len(gp_value_table)
if gp_value_table[vt_length-1][0] and not not gp_value_table[vt_length-1][1]:
new_vt = [[v[0],v[2]] for v in gp_value_table]
input_path = gp_value_table[vt_length-1][0]
new_vt.append([vt_length-1,arcpy.Describe(input_path).baseName])
parameters[0].value = new_vt
return
In this case nothing happens and the 2. column remains emtpy. How can I - row by row - derive the default output name based on the input?