Thank you. I did not know about this option. I have found two mistakes which I corrected. But I still have two more errors, which I do not know how to remove. The errors are:
Traceback (most recent call last):
File "<string>", line 41, in getParameterInfo
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\arcobjects\_base.py", line 94, in _set
(attr_name, self.__class__.__name__))
NameError: The attribute 'list' is not supported on this instance of Filter.
In line 94 I tried to change:
InNeighborhood = "NbrRectangle,3,3,Map"
for
InNeighborhood = NbrRectangle(3, 3, "CELL"),
but it still does not work, so I do not know what is wrong. Any suggestions?
import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "My"
self.alias = "model"
# List of tool classes associated with this toolbox
self.tools = [MyModel]
class MyModel(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "MyModel"
self.description = ""
self.canRunInBackground = True
def getParameterInfo(self):
# Workspace parameter
param0 = arcpy.Parameter(
displayName="Input Workspace",
name="in_workspace",
datatype="DEWorkspace",
parameterType="Required",
direction="Input")
# Set the filter to accept only local (personal or file) geodatabases
param0.filter.list = ["Local Database"]
# First parameter
param1 = arcpy.Parameter(
displayName="Input Raster Dataset",
name="in_rasterdataset",
datatype=["DERasterDataset","DERasterCatalog"],
parameterType="Required",
direction="Input")
param1.filter.list = ["Raster"]
# Second parameter
param2 = arcpy.Parameter(
displayName="Units",
name="units",
datatype="Double",
parameterType="Optional",
direction="Input",
enabled=False)
# Third parameter
param3 = arcpy.Parameter(
displayName="Output Raster Dataset",
name="out_rasterdataset",
datatype=["DERasterDataset","DERasterCatalog"],
parameterType="Derived",
direction="Output")
param3.filter.list = ["Raster"]
param3.parameterDependencies = [param1.name]
param3.schema.clone = True
params = [param0, param1, param2, param3]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
# Import system modules
import arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create()
try:
# Set local variables
InRaster = "in_rasterdataset"
OutRaster = "out_rasterdataset"
InNeighborhood = "NbrRectangle,3,3,Map"
InNoDataOption = "DATA"
# Check out the ArcGIS Spatial Analyst extension license
gp.CheckOutExtension("Spatial")
# Execute FocalStatistics
gp.FocalStatistics_sa(InRaster, InNeighborhood,"", InNoDataOption)
except:
# If an error occured while running a tool, then print the messages.
print gp.GetMessages()
return