I'm trying to achieve a python script to take a TileGrid (fishnet style) of polygons. First I want to add 5 new fields to the shapefile. TileID (Text), YMin (double), YMax (double), XMin (double), and XMax (double). Then the final goal would be to spit a txt file with those fields in the end. Ideally this text file would not include "" and : between the fields. Although, I'm not sure that will be possible.
Now I was able to achieve this (with some success) in ModelBuilder. However, I'd like to put it into an ArcPy code. I had ModelBuilder send out its version of the Python code (attached). However, it is very messy. Would anyone please help me clean this up some? I am very new to Py So I am really insterested in how this should be done.
# Import arcpy module
import arcpy
# Local variables:
Shapefile = ""
Output_Feature_Class__7_ = ""
Output_Feature_Class = ""
Output_Feature_Class__3_ = ""
Output_Feature_Class__4_ = ""
Output_Feature_Class__5_ = ""
Output_Feature_Class__6_ = ""
Output_Feature_Class__2_ = ""
Output_Feature_Class__8_ = ""
Output_Feature_Class__9_ = ""
v2016_lake_cook_county_qquads_shp__2_ = ""
# Process: Add Field
arcpy.AddField_management(Shapefile, "TileID", "TEXT", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
# Process: Add Field (2)
arcpy.AddField_management(Output_Feature_Class__3_, "MinX", "DOUBLE", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
# Process: Add Field (3)
arcpy.AddField_management(Output_Feature_Class__4_, "MaxY", "DOUBLE", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
# Process: Add Field (4)
arcpy.AddField_management(Output_Feature_Class__5_, "MaxX", "DOUBLE", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
# Process: Add Field (5)
arcpy.AddField_management(Output_Feature_Class__6_, "MinY", "DOUBLE", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
# Process: Calculate Field
arcpy.CalculateField_management(Output_Feature_Class__7_, "MinX", "!shape.extent.XMin!", "PYTHON_9.3", "")
# Process: Calculate Field (2)
arcpy.CalculateField_management(Output_Feature_Class, "MaxY", "!shape.extent.YMax!", "PYTHON_9.3", "")
# Process: Calculate Field (3)
arcpy.CalculateField_management(Output_Feature_Class__2_, "MaxX", "!shape.extent.XMax!", "PYTHON_9.3", "")
# Process: Calculate Field (4)
arcpy.CalculateField_management(Output_Feature_Class__8_, "MinY", "!shape.extent.YMin!", "PYTHON_9.3", "")
# Process: Calculate Field (5)
arcpy.CalculateField_management(Output_Feature_Class__9_, "TileID", " [TILE_NAME]", "VB", "")
# Process: Add Attribute Index
arcpy.AddIndex_management(v2016_lake_cook_county_qquads_shp__2_, "TileID;MinX;MaxY;MaxX;MinY", "OutputTest.txt", "UNIQUE", "NON_ASCENDING")