I am still an arcpy newbie, but I think I have a basic understanding of fundamentals including syntax, variables, modules, etc. My question is regarding the usage of parameters while creating a tool.
I am trying to create a tool that will calculate and summarize the area of a feature layer "levels". I have the script working for the calculation and summarization of the feature layer which outputs as a table, but I am not able to get the parameter inputs for the tool working. Syntax checks out (using PyScripter as IDE) but when I try to run the tool in ArcMap "This tool has no parameters" appears. Ideally, I would like the user to input the feature layer "levels" as a parameter and return the summary table, but a message window showing area summary would be even better if thats possible. Please let me know what might be going wrong with the parameters, or how I could change the output to a message window.
import arcpy
class GeoArea(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "GeoArea"
self.alias = "Tom"
# List of tool classes associated with this toolbox
self.tools = [LevelsCalcTool]
class LevelsCalcTool(object):
def __init__(self):
self.label = "LevelsCalcTool"
self.description = "Calculates and summarizes Levels' area in square meters"
self.canRunInBackground = False
def getParameterInfo(self):
param0 = arcpy.Parameter(
displayName="Input Features",
name="in_features",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input"
)
params = [param0]
return params
def execute(self, parameters, messages):
"""The source code of the tool."""
arcpy.AddField_management(params,"area","DOUBLE","#","#","#","#","NULLABLE","NON_REQUIRED","#")
arcpy.CalculateField_management(params,"area","!shape.area@squaremeters!","PYTHON_9.3","#")
arcpy.Statistics_analysis(params, "out_table.dbf", [["area", "SUM"]])
return