2

I am setting up the parameters in a Python toolbox. I have a parameter that I would like to list fields based on a user input feature class. I am wondering if it is possible to list fields based on two feature classes.

def getParameterInfo(self):
 input_data = arcpy.Parameter(
 displayName = "Input data to be fuzzed to a grid",
 name = "input_data",
 datatype = "GPFeatureLayer",
 parameterType = "Required",
 direction = "Input")
 existing_grid = arcpy.Parameter(
 displayName = "Existing Grid",
 name = "site_desc",
 datatype = "GPFeatureLayer",
 parameterType = "Optional",
 direction = "Input")
 output_fields = arcpy.Parameter(
 displayName = "Fields to be Included in Output Fuzzed Data",
 name = "output_fields",
 datatype = "Field",
 parameterType = "Required",
 direction = "Input",
 multiValue = True)
 output_fields.parameterDependencies = [input_data.name]

I would like for the user to be able to also choose fields from the existing_grid dataset, in addition to the input_data dataset.

How do I include the fields from both in the field list?

I tried adding it separately and including it in the brackets, but this just caused the tool parameter to be blank.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 13, 2020 at 16:52
0

1 Answer 1

3

As suggested by @mikewatt in the comments, you'll need to custominze this functionality with arcpy.ListFields. This will need to be done in the updateParameters function. Check for your parameters being altered. If they are, list their fields. Add those fields to your parameter filter.

 def getParameterInfo(self):
 input_data = arcpy.Parameter(
 displayName = "Input data",
 name = "input",
 datatype = "GPFeatureLayer",
 parameterType = "Required",
 direction = "Input")
 existing_grid = arcpy.Parameter(
 displayName = "Existing Grid",
 name = "site_desc",
 datatype = "GPFeatureLayer",
 parameterType = "Optional",
 direction = "Input")
 output_fields = arcpy.Parameter(
 displayName = "Fields to be Included",
 name = "output_fields",
 datatype = "GPString",
 parameterType = "Required",
 direction = "Input",
 multiValue = True)
 output_fields.filter.list = []
 return [input_data, existing_grid, output_fields]
 def updateParameters(self, parameters):
 for i in range (2):
 #check if parameter has been changed
 if not parameters [i].hasBeenValidated:
 #empty list to populate with fields
 flds = []
 #iterate both parameters
 for x in range (2):
 #get parameter
 fc = parameters [x].valueAsText
 #check if parameter has been input
 if fc:
 #get input feature class fields and add to list
 flds += [f.name for f in arcpy.ListFields (fc)]
 #update field input
 parameters [2].filter.list = flds

After one input:

One input feature class

After two inputs:

Two input feature classes

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Jan 14, 2020 at 0:00

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.