AnsweredAssumed Answered

arcpy.GetParameterAsText not passing arguments to the script

Question asked by Hayden_SAEON on May 29, 2019
Latest reply on May 29, 2019 by Hayden_SAEON

I have been working on an arcgis tool which takes the co-ordinate system from an input raster and reprojects a vector to the same co-ordinate system.


The script works fine when i hard code the addresses for the workspace and input datasets. But as soon as I try to pass those as parameters in a toolbox it no longer works.


Can anyone here point out what I am doing wrong?


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 = [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 = arcpy.GetParameterAsText(0)        arcpy.env.workspace = outWorkspace         input_raster = arcpy.GetParameterAsText(1)        input_features = arcpy.GetParameterAsText(2)         output_features = outWorkspace + "\\projected.shp"         out_coordinate_system = arcpy.Describe(input_raster).spatialReference         proj_grid = arcpy.Project_management(input_features, output_features, out_coordinate_system)         return

When I run the tool it provides the following error:

Traceback (most recent call last):  File "<string>", line 75, in execute   File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\", line 1245, in Describe    return gp.describe(value, data_type)  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\", line 370, in describe     self._gp.Describe(*gp_fixargs(args, True)))OSError: "" does not exist  Failed to execute (Tool).

it seems to me that the input variables of the parameters are not being passed correctly.

Any advice would be very appreciated.