Problem with output paramater in script tool - Does not work in model builder!

2262
9
Jump to solution
10-12-2017 09:41 AM
BogiBjornsson
Occasional Contributor

Howdy!

I have a bit of a problem with a python script tool that I am trying to get to work when I chain it to other tools in a model made in model builder. It's just a simple dummy tool I set up to try to sort things out, the model selects a polygon, based on user input via a point type feature set, and buffers this selected polygon (this is the script part) then I wanted to copy the result output (featureclass) to another location by chaining the script tool to the copy features tool but no matter what I try it gives me an error that an input value is required (see model diagram, script tool parameter settings and script tool code below). Script tool runs fine on it's own by the way and gives proper results.

Model diagram:

Copy buffered poylys model diagram

Mybuffers Script tool code:

import arcpy
import os
from arcpy import env

#Set environement variables

scratch = env.scratchGDB
env.overwriteOutput = True
arcpy.SetLogHistory(False) #Important to reduce metadata writing

#Get input parameters

inpnt = arcpy.GetParameterAsText(0)
mypolys = arcpy.GetParameterAsText(1)
outfcname = os.path.join(scratch, "mybuffers")

#Make feature layer from input point(s)

inpntlyrname = "InputPoints"
inpntlyr = arcpy.MakeFeatureLayer_management(inpnt, inpntlyrname)

#Make feature layer from polygons

polylyrname = "MyPolygons"
polylyr = arcpy.MakeFeatureLayer_management(mypolys, polylyrname)

#Select polygons that intersect input points

selpolys = arcpy.SelectLayerByLocation_management(polylyr, "INTERSECT",
                                                  inpntlyr, "25 Meters", "NEW_SELECTION")

#Buffer selected polygons

arcpy.Buffer_analysis(selpolys, outfcname, "5000 Meters")

#Set output parameter

outputfc = arcpy.SetParameterAsText(2, outfcname)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Mybuffers script tool parameters settings (for the output parameter):

Mybuffers output parameter settings

It's like the copy features tool is not getting the data from the script tool even though I've used countless different versions of the SetParameterAsText() and read as much as I can take of the official help. Perhaps there is some good hearted soul willing to look over my code to help me see where I'm going wrong because I'm stuck and getting really annoyed at this

Cheers!

UPDATE 23.10.2017:

I've been relying on the official help in the link below, chapter heading "Derived output that does not modify an input parameter". I have now tested setting up exactly the same example with the post data to repository script tool and the copy features section of the model fails in the exact same way i.e. "input value required", the second tool in the chain does not run.

Setting script tool parameters—Help | ArcGIS Desktop 

0 Kudos
1 Solution

Accepted Solutions
NealBanerjee
Occasional Contributor

I also have this issue and just posted a similar question (before I saw your post).  I still dont understand why the SetParameterAsText doesnt work, but think I found a work around that allows me to use the derived output from the script tool in subsequent Model Builder. 

What I ended up doing was using the 'Calculate Value' tool in model building to build the name of the feature class.  I linked the derived output as a precondition.  In my case my script tool used the 'Create Feature Class' tool based on user input of workspace and output feature class name.  The script tool created and populates the resultant feature class.  

Based on your example I think this approach will work.  Just note that the 'Calculate Value' tool uses some pretty funny syntax - for strings you have to enclose them in "" in addition to the in-line variables %.

Below are some screenshots. 

View solution in original post

9 Replies
DanPatterson_Retired
MVP Esteemed Contributor

not sure why you are using the last parameter as derived

0 Kudos
BogiBjornsson
Occasional Contributor

I am using derived so as not to allow user input for that parameter, basically hiding it from the tool dialog box. I could hard code the parameter inside the script but then I would not get an output which I can subsequently use to chain the script tool in model builder.

0 Kudos
JeevanBasnyat
New Contributor

output : obtained from  in_features

0 Kudos
JeevanBasnyat
New Contributor

HI,  Bogi Bjornsson

I Do not know if you are still searching for the answer, but in mubuffer properties window, i see the properties

type: derived 

Direction : output

Obtained from : blank 

may be you can try setting 

Obtained from : Feature Set . i.e input

derived output is obtained from input.

0 Kudos
BogiBjornsson
Occasional Contributor

Hi there,

Thanks for the input but unfortunately it is not the answer. In the chapter Setting script tool parameters there is a section called "Derived output that does not modify an input parameter". There it specifically states that this parameter "Obtained from" should be empty (see snapshot below).

0 Kudos
JaredSchuckert
Occasional Contributor

Bogi Bjornsson any resolution to this?

0 Kudos
BogiBjornsson
Occasional Contributor

Unfortunately not, no solution has been found.

0 Kudos
NealBanerjee
Occasional Contributor

I also have this issue and just posted a similar question (before I saw your post).  I still dont understand why the SetParameterAsText doesnt work, but think I found a work around that allows me to use the derived output from the script tool in subsequent Model Builder. 

What I ended up doing was using the 'Calculate Value' tool in model building to build the name of the feature class.  I linked the derived output as a precondition.  In my case my script tool used the 'Create Feature Class' tool based on user input of workspace and output feature class name.  The script tool created and populates the resultant feature class.  

Based on your example I think this approach will work.  Just note that the 'Calculate Value' tool uses some pretty funny syntax - for strings you have to enclose them in "" in addition to the in-line variables %.

Below are some screenshots. 

View solution in original post

BogiBjornsson
Occasional Contributor

Interesting workaround, I will try it next time I'm having this problem. Thank you for sharing your solution!

0 Kudos