I would like to be able to create a Python toolbox tool (or a Python script tool) where a choice made from the first parameter (Category in the images below) changes the Display Name of other parameters (which initialize as Sub Category 1 and Sub Category 2 in the images below).
These images are mockups.
After opening the tool I choose Category B for Category.
I would like that choice to change the Display Names of:
- Sub Category 1 to Sub Category B1 (choosing Category A would set Sub Category A1)
- Sub Category 2 to Sub Category B2 (choosing Category A would set Sub Category A2)
Something like below (where I have mocked up the Display Name changes) but with the first parameter green rather than red.
I tried tool validation of a Python script tool first, but seemed to be blocked by the read-only Display Name there. I then moved to a Python Toolbox tool instead because that adds some extra functionality and I was hoping might remove the read-only Display Name limitation.
My attempt to code this as a Python Toolbox tool is below, but it seems not to be working because displayName is read-only there too.
Is there any ArcPy way to meet the requirement that I describe above?
import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [Tool]
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"""
# First parameter
param0 = arcpy.Parameter(
displayName="Category",
name="category",
datatype="String",
parameterType="Required",
direction="Input")
param0.filter.list = ['Category A', 'Category B']
# Second parameter
param1 = arcpy.Parameter(
displayName="Sub Category 1",
name="subcategory_1",
datatype="String",
parameterType="Required",
direction="Input")
# Third parameter
param2 = arcpy.Parameter(
displayName="Sub Category 2",
name="subcategory_2",
datatype="String",
parameterType="Required",
direction="Input")
params = [param0,param1,param2]
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 == "Category A":
parameters[1].displayName = "Sub Category A1"
parameters[2].displayName = "Sub Category A2"
elif parameters[0].value == "Category B":
parameters[1].displayName = "Sub Category B1"
parameters[2].displayName = "Sub Category B2"
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
I am using ArcGIS 10.2.2 for Desktop.