Problems parsing SetParameterAsText

610
3
Jump to solution
11-01-2018 06:02 AM
MollyFoley
Regular Contributor

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

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
MollyFoley
Regular Contributor

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))

View solution in original post

0 Kudos
3 Replies
MollyFoley
Regular Contributor

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))
0 Kudos
Luke_Pinner
MVP Regular Contributor

 You're setting the parameter to outputPDF which is a geoprocessing Result object. Set it to outputPath instead.

0 Kudos
MollyFoley
Regular Contributor

Makes sense, that would work just fine too.

0 Kudos