I have exported a ModelBuilder into a Python script. I am not able to figure it out at which point of the python script I need to make changes so that I can completely run the python script in Python IDE
Here is the ModelBuilder screen shot
Here is the ModelBuilder script exported to Python Script.
# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *
# Load required toolboxes
arcpy.ImportToolbox("Model Functions")
# Local variables:
ElevationContourRingSimply = "W:\\Projects\\FacilityProcessingtest\\ShpPython\\HobokenFlood.gdb\\ElevationContourRingSimply"
Value = "20"
fdcb_Value_ = "W:\\Projects\\FacilityProcessingtest\\ShpPython\\HobokenFlood.gdb\\fdcb%Value%"
fdcb_Value___2_ = fdcb_Value_
fdcb_Value___3_ = fdcb_Value___2_
fdcb_Value___4_ = fdcb_Value___3_
fdcb_Value___5_ = fdcb_Value___4_
fdcb_Value___6_ = fdcb_Value___5_
# Process: For
arcpy.IterateCount_mb("1", "20", "1")
# Process: Select
arcpy.Select_analysis(ElevationContourRingSimply, fdcb_Value_, "GRIDCODE <= %Value%")
# Process: Add Field
arcpy.AddField_management(fdcb_Value_, "WaterLevel", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
# Process: Calculate Field
arcpy.CalculateField_management(fdcb_Value___2_, "WaterLevel", "%Value%", "VB", "")
# Process: Calculate Field (2)
arcpy.CalculateField_management(fdcb_Value___3_, "GRIDCODE", "%Value% - [GRIDCODE] + 1", "VB", "")
# Process: Alter Field
arcpy.AlterField_management(fdcb_Value___4_, "GRIDCODE", "FloodDepth", "FloodDepth", "", "4", "NON_NULLABLE", "false")
# Process: Delete Field
arcpy.DeleteField_management(fdcb_Value___5_, "FID_FloodAllW")
Best Answer
I see several items that will need to be cleaned up. Going from top to bottom...
For example, instead of "%Value%", you will just put Value, i.e., instead of
you will put
or if GRIDCODE is a text column
If you know ahead of time that your final tool will be a script tool, it is more efficient to code it as such from the beginning. Making a model first doesn't save you any time or effort. The only reason I ever do that is if the ESRI documentation on a tool is not very clear (at least to me), and I need to see how a working model actually shows up in python.
I hope this is helpful and gets you started.