[GIS] Making a tool from script, arcpy.Project_management () comes with an error

arcpycoordinate systemerror-000735python-script-tool

I have a script (just a fragment here, up until the line after which the error comes up):

import arcpy
from arcpy import env

arcpy.env.workspace = arcpy.GetParameterAsText(0)    
arcpy.env.overwriteOutput = True

#specify input, output datasets and output coordinate system
input_fc = arcpy.GetParameterAsText(1)
output_fc = arcpy.SetParameterAsText(2, 'ft_mb_afterIteration_lambert')
out_coordinate_system = arcpy.SpatialReference(3308)

#add length column to input datasets
fieldName = "line_length"
arcpy.AddField_management(input_fc, fieldName, "Double")

#project to Lambert and save as new file (for in feature should be Feature Layer / Feature Dataset )
arcpy.Project_management(input_fc, output_fc, out_coordinate_system)

enter image description here

The error is:

Traceback (most recent call last):
  File "H:\Scripts\python\RemoveShortLines.py", line 25, in <module>
    arcpy.Project_management(input_fc, output_fc, out_coordinate_system)
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 8825, in

Project
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000735: Output Dataset or Feature Class: Value is required
Failed to execute (Project).

I have also attached the properties of how I set the tool. I am running this script as a tool.

Essentially at that line where error comes up, the the input dataset (input_fc) is converted to a new dataset (output_fc) with different coordinate system.

Can you suggest why my script is not working?

Best Answer

I would make a slight change to the output_fc and move the SetParameter:

import arcpy
from arcpy import env

arcpy.env.workspace = arcpy.GetParameterAsText(0)    
arcpy.env.overwriteOutput = True

#specify input, output datasets and output coordinate system
input_fc = arcpy.GetParameterAsText(1)
output_fc = 'ft_mb_afterIteration_lambert'
out_coordinate_system = arcpy.SpatialReference(3308)

#add length column to input datasets
fieldName = "line_length"
arcpy.AddField_management(input_fc, fieldName, "Double")

#project to Lambert and save as new file (for in feature should be Feature Layer / Feature Dataset )
arcpy.Project_management(input_fc, output_fc, out_coordinate_system)

arcpy.SetParameterAsText(2, output_fc )
Related Question