arcpy.GetParameterAsText not passing arguments to script?
The code that you have presented is for a Python Toolbox (*.pyt
) for which you need to use the Parameter
class.
GetParameter()
and GetParameterAsText()
are only used with Python Script tools in Standard Toolboxes (*.tbx
).
Using the answer from @PolyGeo my corrected code is as follows:
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 = "Toolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Test_tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
param0 = arcpy.Parameter(
displayName="Input workspace",
name="workspace",
datatype="DEWorkspace",
parameterType="Required",
direction="Input")
param1 = arcpy.Parameter(
displayName="Input classified raster",
name="input_raster",
datatype="GPRasterLayer",
parameterType="Required",
direction="Input")
param2 = arcpy.Parameter(
displayName="Input features",
name="input_features",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
params = [param0, param1, param2]
return params
def execute(self, parameters, messages):
"""The source code of the tool."""
# Define some paths/variables
outWorkspace = parameters[0].valueAsText
arcpy.env.workspace = outWorkspace
output_location = parameters[0].valueAsText
input_raster = parameters[1].valueAsText
input_features = parameters[2].valueAsText
output_features = output_location + "\\projected.shp"
out_coordinate_system = arcpy.Describe(input_raster).spatialReference
proj_grid = arcpy.Project_management(input_features, output_features, out_coordinate_system)
return