I am trying to create a derived output parameter for a Python script tool so that the output will show in a model (I want to use the output folder as an input for another tool). I want this output to be a folder that is the same as an input folder after geoprocessing has put the results (outShapeFiles) into that folder. Essentially, I have 4 initial parameters, one of which is the outFolder = sys.argv[4]. At the end of the code, I set `outFolder = arcpy.SetParameterAsText(5, "Output Features"). When I run it, everything works but the last part (the outShapefiles are created and put into the outFolder). I get this error message: "RuntimeError: Object: Error in setting parameter as text." Here is the code. Can you see how I can resolve this error so that my output parameter can be viable in a model? Note how I set outFolder at the end.
input_FC = sys.argv[1]
inField = sys.argv[2]
theFName = sys.argv[3]
outFolder = sys.argv[4] #Set as an input parameter in the script tool
script = sys.argv[0]
msg = "\nRunning: ... {}".format(script)
arcpy.AddMessage(msg)
arcpy.env.overwriteOutput = True
...
...
aMax = 1
for aVal in valueList:
aMax = max(aMax, len(str(aVal)))
for aVal in valueList:
if (str(aVal).isdigit()) and (not inType == "String"):
fs = '"' + "%" + str(aMax) + "." + str(aMax) + 'i"'
aSuffix = fs % aVal
aVal = str(aVal)
elif inType == "Double" and inScale == 0:
aSuffix = str(aVal).replace(".0","") ######
aVal = str(aVal).replace(".0","")
else:
aSuffix = str(aVal)
aVal = str(aVal)
try:
aSuffix = aSuffix.replace(" ","_") #replace garbage in output files
aSuffix = aSuffix.replace('"',"")
aSuffix = aSuffix.replace("/","")
aSuffix = aSuffix.replace("-","")
outName = theFName + aSuffix + ".shp"
outShapeFile = outFolder + "/" + outName
outShapeFile = outShapeFile.replace("\\","/")
#
#Create a query and produce the file
if (not aVal.isdigit()) or (inType == "String"):
aVal = "'" + aVal + "'"
whereClause = "%s = %s" % (inField, aVal)
arcpy.MakeFeatureLayer_management(input_FC, "TempLayer", whereClause)
arcpy.CopyFeatures_management("TempLayer",outShapeFile)
arcpy.AddMessage("Output and query: " + outShapeFile + " " +
whereClause)
except:
whereClause = "%s = %s" % (inField, aVal)
arcpy.AddMessage("Output and query: " + outShapeFile + " " +
whereClause + " did not work ")
arcpy.SetParameterAsText(5, outFolder) #This is where I try to
make outFolder an output parameter. I have set it to derived from the input "outFolder".
arcpy.AddMessage("\n Processing complete" + "\n")
del arcpy

sys.argvuses an index starting with zero, so technically, countingsys.argv[0], outFolder as an output would be the 6th parameter defined. Basically, I got the same error. I am confused on this point since I am trying to usesys.argvandarcpy.SetParametersAsTextin the same script.