AnsweredAssumed Answered

Update value table based on selection in multivalue value list - Python Toolbox

Question asked by cbalmus on Jul 20, 2015
Latest reply on Jul 24, 2015 by wwmiller68

Hi,

I need a value list which allows the user to select multiple values. Based on this selection, I need to update the first column of a value table with 2 columns. The second column is meant for the user to input values. I am trying this in a Python toolbox.

My code looks something like that at this point:

 

 

import arcpy
class Tool(object):
def __init__(self):
  
"""Define the tool (tool name is the name of the class)."""
  self
.label = "Tool"
  self
.description = ""
  self
.canRunInBackground = False

def getParameterInfo(self):
  
"""Define parameter definitions"""
  param0
= arcpy.Parameter(
  displayName
= "Select Fruit",
  name
= "Fruit_selection",
  datatype
= "GPString",
  parameterType
= "Required", 
  direction
= "Input",
  multiValue
=True) 
  param0
.filter.type = "ValueList"
  param0
.filter.list = ["Apple","Pear","Peach"]

  param1
= arcpy.Parameter(
  displayName
= "Selection",
  name
= "Value_table",
  datatype
= "GPValueTable",
  parameterType
= "Required", 
  direction
= "Input") 
  param1
.columns =([["String", "Fruit_name"], ["Long","Fruit_price"]])

  params
= [param0,param1]
  
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."""

  vtab
= []
 
if str(parameters[0].value) == ["Apple"]:
    vtab
.append(["Jonathan",2500])
    vtab
.append(["Gold",1000])
    parameters
[1].values = vtab
 
elif str(parameters[0].value) == ["Pear"]:
    vtab
.append(["Anjou",1000])
    vtab
.append(["Concorde",2000])
    parameters
[1].values = vtab
  
return

def updateMessages(self, parameters):
  
"""Modify the messages created by internal validation for each tool
  parameter. This method is called after internal validation."""

  
return

def execute(self, parameters, messages):
  
"""The source code of the tool."""
  
return

 

 

Any help would be much appreciated.

 

Thank you!

Outcomes