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
78.6k57 gold badges260 silver badges407 bronze badges
asked Feb 3, 2020 at 18:18
2
  • numCol definition is missing. Commented Feb 4, 2020 at 0:47
  • Previously. It’s an integer (5 to be exact). Commented Feb 4, 2020 at 3:16

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.