Models that contain script tools that return output parameters are not being exported to Python properly

Last Published: April 25, 2020


Models that contain script tools that return output parameters are not being exported to Python properly. As an example, the following steps results in an erroneous python script.

1. Create a simple Python script with an output parameter of type double:

import win32com.client, sys, string
GP = win32com.client.Dispatch("esriGeoprocessing.GPDispatch.1")

2. Import the script into a toolbox and set the output parameter on the parameter tab. Name the script custom_gp_tool.

3. Create a new model and drag and drop the script tool into it. Attach the output of the script tool into any tool that will accept it. For example, 'Simplify Line'. Use the output parameter of the script as the value for the 'simplification tolerance'.

4. Run the model. This portion of the operation is successful.

5. Export the model to a script. The exported script hard codes a variable representing the output parameter of the first script tool, which is incorrect:

# ---------------------------------------------------------------------------
# model_to_script.py
# Created on: Fri Oct 14 2005 11:36:54 AM
# (generated by ArcGIS/ModelBuilder)
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, win32com.client

# Create the Geoprocessor object
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
gp.overwriteoutput = 1

# Set the necessary product code

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
# Local variables...
my_output = "100"
rivers_shp = "C:\\ESRI\\ESRIDATA\\MEXICO\\rivers.shp"
Output_Feature_Class = "C:\\ESRI\\ESRIDATA\\MEXICO\\rivers_SimplifyLine.shp"
Output_Point_Feature_Class = "C:\\ESRI\\ESRIDATA\\MEXICO\\rivers_SimplifyLine_Pnt.shp"

# Process: custom_gp_tool...
gp.toolbox = "C:/Temp/MyToolBox.tbx"

# Process: Simplify Line...
gp.SimplifyLine_management(rivers_shp, Output_Feature_Class, "POINT_REMOVE", my_output,

The line, gp.custom_gp_tool() in bold above is essentially meaningless because the output has been hard-coded into a variable. The script used in custom_gp_tool as an example is very basic and is for demonstration purposes only. However, if it did calculations based on inputs, current date, random numbers, etc., the output would never reach the SimplifyLine tool.


This is a known issue.


Manually change the exported script.




my_output = gp.custom_gp_tool()

    Article ID:000008624

    • ArcMap 9 x

    Get help from ArcGIS experts

    Contact technical support

    Download the Esri Support App

    Go to download options

    Discover more on this topic