Examples or documentation for Outputs in .pyt Python Toolboxes?

357
2
05-03-2017 09:55 AM
FredKellner2
New Contributor II

I'm having a devil of a time figuring out how outputs in ESRI Python toolboxes work. I can't either find usable examples or the proper documentation.

My aim is this

1.) Allow the user to navigate to a gdb and provide a name for the output of the toolbox, from the toolbox dialog

2.) have the toolbox return results that aren't empty!

I've tried everything under the sun. I simply want to provide the path and name that user provides from the dialog to this function.

arcpy.MakeFeatureLayer_management(inp, outname,'"RND" = 1')

where outname is the user provided parameter

and have the results of this function be returned as an output of the tool.

Currently all that is returned is an empty FC.

However when I run the logic of the code in the python window and predifine all the parameters I get the results I desired. So I am assuming that its error on my part on how the input parameters are being handled in the getParameterInfo(self) of the tbx.

I've attached my code

0 Kudos
2 Replies
LeandraGordon
Occasional Contributor

I had a quick look and the main difference I can see is that I have

import arcpy,os
# Set overwrite option
arcpy.env.overwriteOutput = True
up the top of my script. Also, if the toolbox is loaded in ARCGIS Pro, right click and check the parameters in ARCGIS Pro. 
Otherwise it's a little hard to debug the code unless you are more specific about which inputs/outputs you are having trouble with.
0 Kudos
JohannesLindner
Occasional Contributor II

MakeFeatureLayer creates a layer from the given feature class. A layer is not permanent and can only be saved in the project.

What you want is a feature class, which can be saved to a gdb or to your file system ( as shape file). Luckily, you can easily convert the layer into a feature class.

Change this line:

arcpy.MakeFeatureLayer_management(inp, outname,'"RND" = 1')

into:

layer = arcpy.MakeFeatureLayer_management(inp, 'some_random_layer_name','"RND" = 1')

arcpy.CopyFeatures_management(layer, outname)


Have a great day!
Johannes