2

I am writing a python script within an ArcGIS toolbox (not a Python Toolbox), that takes as input, a multivalue parameter of feature classes from which I would like to populate a second parameter with a drop down list of fields from the first feature class in the multivalue list. When using a single feature class as input, the field parameter can simply be set using the "Obtained from" functionality in the "Parameters" tab, but not so with a multivalue input. I am attempting to perform the operation using the validation classes instead. Below is my attempt using the "updateParameters" class. The validation doesn't fail, but doesn't produce a list of fields as expected. Any thoughts?

def updateParameters(self):
  """Modify the values and properties of parameters before internal
  validation is performed.  This method is called whenever a parameter
  has been changed."""

  if self.params[0].value:
      self.params[1].filter.list = arcpy.ListFields(self.params[0].valueAsText.split(";")[0])
  return

Edit - I’ve also tried:

[f.name for f in arcpy.ListFields(self.params[0].valueAsText.split(";")[0])]

With no success

  • List fields returns fields, you need their names. – FelixIP Apr 27 '18 at 4:42
  • Thanks Felix. I’ve tried that too, but it didn’t work either. Unless my syntax was wrong. I’ve edited my question code to reflect that. – Jae Apr 27 '18 at 8:39
  • Perhaps try to change type of 2nd parameter gis.stackexchange.com/questions/217192/… – FelixIP Apr 27 '18 at 9:54
1

This validation works:

  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    if self.params[0].value:
      lyr=self.params[0].valueAsText.split(";")[0]
      aList=[f.name for f in arcpy.ListFields(lyr)]
      self.params[1].value=aList
    return

if you launch tool from current mxd. Parameter of interest:

enter image description here

However, using hidden parameter (2) that is taking 1st entry from multiple layers list:

  def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""
    self.params[2].enabled=0
    self.params[2].category = "Information Only"
    return

  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    if self.params[0].value:
      lyr=self.params[0].valueAsText.split(";")[0]
      self.params[2].value=lyr  
    return

Gives you more flexibility, because you'll be able to use filter on field types on parameter1 while obtaining fields from hidden.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.