Select to view content in your preferred language

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

3604
3
07-20-2015 11:48 PM
CristinaBalmus
New Contributor

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!

Tags (2)
3 Replies
WesMiller
Regular Contributor III
0 Kudos
CristinaBalmus
New Contributor

Thank you, Wes Miller! I have already seen and used the info on the page you suggested, but this is for a simple drop-down. I need it for a multivalue list.

Regards,

0 Kudos
WesMiller
Regular Contributor III

You can set your tool box to accept multi-values and write you dependencies for the multi-values

0 Kudos