Model exported to python won't run - Includes IterateFieldValues and FC to FC

1166
5
05-24-2011 09:59 AM
SarahSullivan
New Contributor
I created three models and exported them to python hoping that I could create a batch file to auto-run them in sequence.  The first two are fine and work without a problem.  The third works properly as a model in ArcView but once exported as python script, won't run.  I haven't changed it at all and even tried re-exporting just in case.  (Well, it might be running but it's not producing anything.)  Any suggestions?  Is it possible that Iterate Field Values won't work outside of Arc?

# Import arcpy module
import arcpy

# Load required toolboxes
arcpy.ImportToolbox("Model Functions")

# Local variables:
ProcessArea = "M:\\GISData\\CFNData\\FiberRoutes\\FiberSource\\ProcessArea"
tblRouteSegments = "C:\\GISData\\FiberRoutes.mdb\\tblRouteSegments"
tblActivePublicProviderList = "C:\\GISData\\FiberRoutes.mdb\\tblActivePublicProviderList"
Value = "1.shp"

# Process: Iterate Field Values
arcpy.IterateFieldValues_mb(tblActivePublicProviderList, "ProviderID", "String", "true", "true", "")

# Process: Feature Class to Feature Class
arcpy.FeatureClassToFeatureClass_conversion(tblRouteSegments, ProcessArea, Value, [FieldMap...], "")
Tags (2)
0 Kudos
5 Replies
JasonScheirer
Occasional Contributor III
Any model with an iterator will not correctly export to a script.
0 Kudos
SarahSullivan
New Contributor
Why is that?  And is there a way to work around it?
0 Kudos
JasonPardy
New Contributor
Unfortunately, this is not supported and is documented here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Exporting_a_model/002w00000031000000/

The best solution is to call your model tool from a Python script:

import arcpy

arcpy.ImportToolbox(path to the toolbox contain the model tool)

arcpy.ModelToolName(parameters)
0 Kudos
MaxSquires
Occasional Contributor
Unfortunately, this is not supported and is documented here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Exporting_a_model/002w00000031000000/

The best solution is to call your model tool from a Python script:

import arcpy

arcpy.ImportToolbox(path to the toolbox contain the model tool)

arcpy.ModelToolName(parameters)



From Above Link --
If your model used any inline variable substitution such as %workspace%, %scratchworkspace%, %n%, %i%, or %variable name%, those will have to be substituted with the correct value.
If your model used an iterator, the iteration logic will not be exported and will have to be replaced with the looping statements in Python.

I don't think the 'documentation' is very forthcoming on this.  It seems that when a model is exported to python that includes incompatible calls to arcpy functions arcgis should inert a comment in the python code explaining why it won't work, or trhow a warning when exporting such models. 

Do you mean that putting the model that iterates a selection of attributes, in a saved toolbox, then importing the toolbox and the model will get around the limitation of using 'model only' tools in python?

Thanks.
0 Kudos
JasonScheirer
Occasional Contributor III
Yes. If you import the toolbox using ImportToolbox and call the model you will get iteration.
0 Kudos