How to Execute "Batch Zone Stats as Table" Python file in ArcGIS 9.2

Discussion created by suhaibfarhan on Sep 22, 2012
Hello Everyone

I'm fairly new to python scripting but I downloaded and modified Batch Zonal Statistics as Table script.

I'm trying to obtain statistics within 10 zonal areas from roughly 5000 rasters. But actually i really dont know how to execute the below mentioned python file. What i did yet:

In ArctoolBox (ArcGIS 9.2) add a new toolbox and then add a new script to the tool, but when i run this python file it gives me this error message "This tool has no parameters".  Kindly help in this regard to let me know how to add or execute this script into arctool box. thanks in advance

The Python Script is as below:

# Create the Geoprocessor object
import win32com.client, sys, os, string

gp = win32com.client.Dispatch("esriGeoprocessing.GPDispatch.1")
# Check out Spatial Analyst extension license
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
gp.OverwriteOutput = 1

    gp.Workspace = "d:/test"  #set workspace folder
    InZonalLayer = "d:/test/data/uib.gdb/catchment" #input zone layer, zone layer is a raster
    InZonalValueField = "Name" #specify which field to be used from zone layer
    #set output workspace
    OutWorkSpace = "d:/test/data/uib.gdb/tables"

    #Get the raster datasets in the input workspace and loop through them from the start
    InputRasters = gp.ListRasters()
    InputRaster =

    while InputRaster:
        strInputRaster = str(InputRaster) #string from raster file name
        strDate = strInputRaster[19:-7] #date obtained from raster file name
        print strDate
        strOutputTableName = strInputRaster[0:-4]#output table name from raster

        strOutTablePath = OutWorkSpace + "/" + strOutputTableName + ".dbf"    
        print strOutTablePath       

        # Process: Zonal Statistics as Table
        gp.ZonalStatisticsAsTable_sa(InZonalLayer, InZonalValueField, InputRaster, strOutTablePath, "DATA")
        #add new field to dbf table
        strFieldName = "RAST_DATE"         # variable becomes a string
        strDataType = "TEXT"               # variable becomes a string
        strAlias = "DATE"                  # variable becomes a string
        intFieldLength = 20                # variable becomes an integer

        #Add new field and populate the field with date from rasters
        gp.CalculateField_management(strOutTablePath,"RAST_DATE", strDate,"VB")

        #append to gdb table already created

        #go to the next raster and loop again
        InputRaster =
    print gp.GetMessages(2)