5

Similar to Set default values for value table in Python Toolbox tool, I'm trying to populate a value table with default values. However for the linked question the value table is populated once an input feature class is input. I'm trying to add default values once the first value of the value table has been added. Here's my parameters:

class Tool(object):
    def __init__ (self):
        self.label = "Fast Field Calculate"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo (self):
        inTab = arcpy.Parameter (
            displayName = "Input Table",
            name = "table",
            datatype = "DETable",
            parameterType = "Required",
            direction = "Input")

        calcs = arcpy.Parameter(
            displayName= "Update Field",
            name= "calcs",
            datatype= "GPValueTable",
            parameterType= "Required",
            direction= "Input")

        letters = string.ascii_uppercase [:numCol]
        calcs.parameterDependencies = ["table"]
        clmns = ["String", "Update Field"]
        clmns = [clmns] + [["String", "Calc Field '{}'".format (a)] for a in letters]
        clmns = clmns + [["String", "Logic Test"], ["String", "Equation"], ["String", "Null Values"]]
        calcs.columns = clmns
        calcs.filters [-1].list = ["TREAT AS NULL", "TREAT AS ZERO", "SKIP COMPUTATION"]

Here is the updateParameters function where I'm trying to create default values:

def updateParameters(self, parameters):
    inTab, calcs = parameters
    if inTab.altered and not inTab.hasBeenValidated:
        fc = inTab.valueAsText
        inFlds = arcpy.ListFields (fc)
        flds = ["-"] + [f.name for f in inFlds]
        for i in range (numCol + 1):
            if i == 0:
                fldFlds = list (flds)
                fldFlds.remove ("-")
                calcs.filters [i].list = fldFlds
                continue
    if inTab.altered and inTab.value and calcs.values:
        fc = inTab.valueAsText
        inFlds = arcpy.ListFields (fc)
        flds = ["-"] + [f.name for f in inFlds]
        for i in range (numCol + 1):
            if not calcs.values [-1] [i]:
                calcs.values [-1] [i] = "-" ##doesn't work - no default value displayed
            calcs.filters [i].list = flds
        if not calcs.values [-1] [-1]:
            calcs.values [-1] [-1] = "TREAT AS NULL" ##doesn't work - no default value

However, none of the values in the value table get populated. Is there a way to populate default values in a value table once the first value has been input?

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
Emil Brundage
  • 13,859
  • 3
  • 26
  • 62

0 Answers0