2

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.

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

Error I receive:

Traceback (most recent call last): File "D:\NET_Projects\HabitatMapGPServices\PrintHabitatMaps\PrintHabitatMaps.py", line 234, in 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

My input window: enter image description here

How my output is set up:

enter image description here

2
  • 1
    Try arcpy.SetParameterAsText(7, str(outputPDF))
    – KHibma
    Nov 1, 2018 at 13:42
  • @KHibma - Thanks, that did it. That never would have occurred to me...
    – MKF
    Nov 1, 2018 at 14:00

1 Answer 1

3

You need to pass a string to your derived output parameter.

Ie. arcpy.SetParameterAsText(7, str(outputPDF))

The result from outputPDF = arcpy.mapping.ExportToPDF(mxd, outputPath) isn't something you can pass directly to the output. Alternatively you could have passed outputPath as that is a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.