Script Tool Return Value

1491
5
08-11-2011 08:59 AM
JeffWard
Occasional Contributor III
Hi,

I am trying to set up a model to do a task that I do every month.  Part of that model is a stand-alone python script that creates a file name with the date tagged on to the end of it.  How do I write my script so that it returns this string and I can use it as input for another geoprocessing tool?  I have searched the forums and help, but can't find any examples of this.

Any help is much appreciated.

Jeff
Jeff Ward
Summit County, Utah
0 Kudos
5 Replies
MikeMacRae
Occasional Contributor III
Are you trying to use the current date or a date that you want to set?

If so, try importing datetime, create the date and then pass it to a string variable. From there, build your file name and concatenate your string date variable where you want it.

x = str(yourdatevariable)


Here are some good examples on how datetime works.

http://www.saltycrane.com/blog/2008/06/how-to-get-current-date-and-time-in/
0 Kudos
JasonScheirer
Occasional Contributor III
You can set up an output parameter of type string and then use SetParameterAsText to populate the value at the end of your script.
0 Kudos
JeffWard
Occasional Contributor III
Thanks for the quick responses.  After looking into the output parameter, I have added my script to the model as a script tool and created an output parameter as a string type.  The file name is hard coded into the script, so I don't have any parameters in the script.  Do I need to create one for the setParameterAsText?  Can you point me to some examples of what the a script with an output parameter looks like and I can figure out how to plug it into the model?

Thanks again for the quick replies.
Jeff Ward
Summit County, Utah
0 Kudos
DaleHoneycutt
Occasional Contributor III
See Setting script tool parameters.  It appears you want a single derived output parameter, so pay particular attention to the write-ups about derived output parameters.
0 Kudos
JeffWard
Occasional Contributor III
Thanks everyone for your help.  Thanks for that link Dale, that is what I needed to get what I was calling a return value.  I created a derived output string parameter for my script tool and added this line to the end of my script: arcpy.SetParameterAsText(0, fileName).

Thanks again.
Jeff Ward
Summit County, Utah
0 Kudos