Hi all,
I am trying to create an ArcGIS Pro python tool that prepopulates a list with field names from an imported shapefile. I want to be able to delete field names from the list, but the tool I have created won't allow it. I am guessing that I need to add some type of update part to the script, but just not sure. In the tool, a red "X" appears next to each field name, but when clicked does not actually delete the field name. Any help would be appreciated. here is the tool as it currently exists:
class FieldNames(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "FieldNames"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
fc = arcpy.Parameter(
displayName="fc",
name="fc",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
names = arcpy.Parameter(
displayName="field names",
name="fields",
datatype="GPString",
parameterType="Required",
direction="Input"
)
names.parameterDependencies = [fc.name]
names.multiValue = True
params = [fc,names]
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."""
# This comes from here https://gis.stackexchange.com/questions/330672/deriving-field-parameter-from-table-parameter-in-python-toolbox
if parameters[0].altered:
parameters[1].values = [field.name for field in arcpy.ListFields(parameters[0].valueAsText)]
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."""
# sat = parameters[0]
fc = parameters[0].valueAsText
fields = parameters[1].valueAsText
return