I have a really basic script that selects an input Polygon by an Attribute and then does a series of Buffers on that, a select by location and then appends the result into a final output. I need to run this process through each feature individually. I created a tool parameter for the initial Select By Attribute, but how do I alter this script to loop through all features rather than manually altering the SQL statement?
Code below:
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# IndexMask_Standard_SQL.py
# Created on: 2015-09-02 09:01:40.00000
# (generated by ArcGIS/ModelBuilder)
# Usage: IndexMask_Standard_SQL <Expression>
# Description:
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
# Script arguments
Expression = arcpy.GetParameterAsText(0)
if Expression == '#' or not Expression:
Expression = "PageNumber = 11" # provide a default value if unspecified
# Local variables:
IndexPoly = "IndexPoly"
IndexPolys__3_ = IndexPoly
IndexPolys_Buffer5_Buffer_Mu1__3_ = IndexPolys__3_
IndexPolys_Buffer5 = "C:\\Users\\bwhiteley\\Documents\\ArcGIS\\Default.gdb\\IndexPolys_Buffer5"
IndexPolys_Buffer5_Buffer = "C:\\Users\\bwhiteley\\Documents\\ArcGIS\\Default.gdb\\IndexPolys_Buffer5_Buffer"
IndexPolys_Buffer5_Buffer_Mu = "C:\\Users\\bwhiteley\\Documents\\ArcGIS\\Default.gdb\\IndexPolys_Buffer5_Buffer_Mu"
IndexPolys_Buffer5_Buffer_Mu1 = "IndexPolys_Buffer5_Buffer_Mu"
IndexMask_Export__3_ = IndexPolys_Buffer5_Buffer_Mu1__3_
IndexMask_Export = "C:\\Users\\bwhiteley\\Documents\\ArcGIS\\Default.gdb\\IndexMask_Export"
# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management(IndexPoly, "NEW_SELECTION", Expression)
# Process: Buffer
arcpy.Buffer_analysis(IndexPolys__3_, IndexPolys_Buffer5, "150 Feet", "OUTSIDE_ONLY", "ROUND", "NONE", "", "PLANAR")
# Process: Buffer (2)
arcpy.Buffer_analysis(IndexPolys_Buffer5, IndexPolys_Buffer5_Buffer, "5000 Feet", "OUTSIDE_ONLY", "ROUND", "NONE", "", "PLANAR")
# Process: Multipart To Singlepart
arcpy.MultipartToSinglepart_management(IndexPolys_Buffer5_Buffer, IndexPolys_Buffer5_Buffer_Mu)
# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(IndexPolys_Buffer5_Buffer_Mu, IndexPolys_Buffer5_Buffer_Mu1, "", "", "OBJECTID OBJECTID VISIBLE NONE;SHAPE SHAPE VISIBLE NONE;PageNumber PageNumber VISIBLE NONE;ScaleRelative ScaleRelative VISIBLE NONE;ScaleDescription ScaleDescription VISIBLE NONE;Rotation Rotation VISIBLE NONE;PageName PageName VISIBLE NONE;SHAPE_Length SHAPE_Length VISIBLE NONE;SHAPE_Area SHAPE_Area VISIBLE NONE;BUFF_DIST BUFF_DIST VISIBLE NONE;ORIG_FID ORIG_FID VISIBLE NONE;SHAPE_length SHAPE_length VISIBLE NONE;SHAPE_area SHAPE_area VISIBLE NONE")
# Process: Select Layer By Location
arcpy.SelectLayerByLocation_management(IndexPolys_Buffer5_Buffer_Mu1, "INTERSECT", IndexPolys__3_, "", "NEW_SELECTION", "INVERT")
# Process: Append
arcpy.Append_management("IndexPolys_Buffer5_Buffer_Mu", IndexMask_Export, "NO_TEST", "PageName \"PageName\" true false false 25 Text 0 0 ,First,#,IndexPolys_Buffer5_Buffer_Mu,PageName,-1,-1;SHAPE_Length \"SHAPE_Length\" false true true 8 Double 0 0 ,First,#,IndexPolys_Buffer5_Buffer_Mu,SHAPE_Length,-1,-1;SHAPE_Area \"SHAPE_Area\" false true true 8 Double 0 0 ,First,#,IndexPolys_Buffer5_Buffer_Mu,SHAPE_Area,-1,-1", "")