Getting zmin zmax of a raster parameter in a tool validation in ArcGIS Desktop 10.7 toolbox Python script

Jump to solution
01-14-2021 04:43 AM
New Contributor II

I am developing a python script tool (my first one). The tool has 3 input parameters:

  1. a raster
  2. z min
  3. z max

I am trying to get automatically z min and z max after the user specify the raster using the validation script but I got this error: TypeError: expected a raster or  layer

This is my code (commented lines are other attempts I tried without results):

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].altered:
  if self.params[0].value:
    #rst_ds = self.params[0]
    rst_ds = self.params[0].value
    self.params[1].value = arcpy.Raster(rst_ds).minimum

    #self.params[2].value = arcpy.Raster(rst_ds.replace('\\','/')).maximum
    #arcpy.MakeRasterLayer_management(rst_ds, "rst_lyr")
    #self.params[1].value = arcpy.Raster("rst_lyr").minimum



0 Kudos
1 Solution

Accepted Solutions
MVP Notable Contributor
2 Replies
MVP Esteemed Contributor

Code formatting ... the Community Version - GeoNet, The Esri Community

def updateParameters(self):

Use python for the language... It will make your def happy again

def updateParameters(self):

 The parameter type would be "any" and you have to deal with either a raster or a number being added

... sort of retired...
0 Kudos
MVP Notable Contributor