BUG
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:
Code:
import win32com.client, sys, string
GP = win32com.client.Dispatch("esriGeoprocessing.GPDispatch.1")
GP.SetParameterAsText(0,"100")
Code:
# ---------------------------------------------------------------------------
# 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
gp.SetProduct("ArcEditor")
# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
gp.AddToolbox("C:/Temp/MyToolBox.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"
gp.custom_gp_tool()
# Process: Simplify Line...
gp.SimplifyLine_management(rivers_shp, Output_Feature_Class, "POINT_REMOVE", my_output,
"FLAG_ERRORS", "KEEP_COLLAPSED_POINTS")
Code:
gp.custom_gp_tool()
Code:
my_output = gp.custom_gp_tool()
Get help from ArcGIS experts
Download the Esri Support App