I think I have all my indexing correct.
I have 8 parameters in my script tool. 7 input and 1 derived output. Indexing for GetParameterAsText starts at 0, so logically my SetParameterAsText should have an index of 7, considering my output parameter is the last one in the list.
I use sys.argv to set my input parameters in the script. This index starts at 1.
My script:
#Get all the inputs from the user
year = sys.argv[1] #GetParameterAsText(0)
state = sys.argv[2] #GetParameterAsText(1)
cipArea = sys.argv[3] #GetParameterAsText(2)
layerString = sys.argv[4] #GetParameterAsText(3)
renderer = sys.argv[5] #GetParameterAsText(4)
orientation = sys.argv[6] #GetParameterAsText(5)
emailAddr = sys.argv[7] #GetParametersAsText(6)
#Do a ton of stuff
outputPath = os.path.join(arcpy.env.scratchFolder, "Map.pdf")
outputPDF = arcpy.mapping.ExportToPDF(mxd, outputPath)
arcpy.SetParameterAsText(7, outputPDF)
How the output parameter is set (there are 8 parameters, I just can't expand the window to show them all):
Input window (don't mind the x's):
Anybody know what could be happening? This is the error I get back:
Traceback (most recent call last):
File "D:\NET_Projects\HabitatMapGPServices\PrintHabitatMaps\PrintHabitatMaps.py", line 234, in <module>
arcpy.SetParameterAsText(7, outputPDF)
File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\__init__.py", line 670, in SetParameterAsText
return gp.setParameterAsText(index, text)
File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\geoprocessing\_base.py", line 231, in setParameterAsText
self._gp.SetParameterAsText(*gp_fixargs(args, True)))
AttributeError: Object: Error in parsing arguments for SetParameterAsText
Solved! Go to Solution.
So, when setting parameter as text, you have to make sure the output is actually a string. In my case it was not, so the script should look like this:
arcpy.SetParameterAsText(7, str(outputPDF))
So, when setting parameter as text, you have to make sure the output is actually a string. In my case it was not, so the script should look like this:
arcpy.SetParameterAsText(7, str(outputPDF))
You're setting the parameter to outputPDF which is a geoprocessing Result object. Set it to outputPath instead.
Makes sense, that would work just fine too.