Esri / collector-tools

A set of python scripts and geoprocessing tools to automate common tasks and workflows in conjunction with Collector for ArcGIS
Apache License 2.0
74 stars 35 forks source link

validation fix #70

Closed apulverizer closed 5 years ago

apulverizer commented 5 years ago

Fixes #68

Changes the validation logic in recreate_geometry.py script tool from:

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."""

    # Attempt to auto-populate the fields based on their names
    if self.parameters[0].altered:
      in_field_names = [field.name for field in arcpy.Describe(self.parameters[0].valueAsText).fields if
                        field.type in ("Double", "Long", "Short", "Integer", "Single", "SmallInteger")]
      for field_name in in_field_names:
        if any(x in field_name.lower() for x in ("longitude", "long")) or "x" == field_name.lower():
          self.parameters[2].value = field_name
          break
      for field_name in in_field_names or "long" in field_name.lower() or "y" == field_name.lower():
        if any(x in field_name.lower() for x in ("latitude", "lat")):
          self.parameters[3].value = field_name
          break
      for field_name in in_field_names:
        if any(x in field_name.lower() for x in ("elevation", "elev", "altitude", "height", "depth")) or \
                        "z" == field_name.lower():
          self.parameters[4].value = field_name
          break
    return

to

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."""

    # Attempt to auto-populate the fields based on their names
    if self.parameters[0].altered:
      in_field_names = [field.name for field in arcpy.Describe(self.parameters[0].valueAsText).fields if
                        field.type in ("Double", "Long", "Short", "Integer", "Single", "SmallInteger")]
      for field_name in in_field_names:
        if any(x in field_name.lower() for x in ("longitude", "long", "x")) and not self.parameters[2].altered:
          self.parameters[2].value = field_name
          break
      for field_name in in_field_names:
        if any(x in field_name.lower() for x in ("latitude", "lat", "y")) and not self.parameters[3].altered:
          self.parameters[3].value = field_name
          break
      for field_name in in_field_names:
        if any(x in field_name.lower() for x in ("elevation", "elev", "altitude", "height", "depth", "z")) and not self.parameters[4].altered:
          self.parameters[4].value = field_name
          break
    return

Basically if there is a value already specified for a parameter, then don't update it. Previously anytime there was a change, the value was being overwritten.