I am trying to loop through records of a feature class with same site number ID's, perform a set of arcpy functions, and stop loop and continue on with later code once max ID is met.
I used a cursor to find and set a max value variable of largest number from feature class Site ID field and then a for loop to iterate over the feature class to select records with the same site ID, perform acouple of functions and then stop once max value is met. Problem is the code keeps looping/creating FC's past the max value (which is 37 in the attribute table). Any advice?
Code Below:
arcpy<SPAN class="punctuation token">.</SPAN>CreateFeatureDataset_management<SPAN class="punctuation token">(</SPAN>Output_Location<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"MapGrids"</SPAN><SPAN class="punctuation token">,</SPAN>spatref<SPAN class="punctuation token">)</SPAN>
max_value <SPAN class="operator token">=</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">999999</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Merged_Assets"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Site_Num"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
max_value <SPAN class="operator token">=</SPAN> max<SPAN class="punctuation token">(</SPAN>int<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> max_value<SPAN class="punctuation token">)</SPAN>
count <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">if</SPAN> count <SPAN class="operator token"><=</SPAN> <SPAN class="punctuation token">(</SPAN>max_value<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Merged_Assets"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'"Site_Num" = \'{0}\''</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>count<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>GridIndexFeatures_cartography<SPAN class="punctuation token">(</SPAN>Output_Location <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\MapGrids"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\Site"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>count<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Merged_Assets"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"INTERSECTFEATURE"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"USEPAGEUNIT"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>Output_Location <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\MapGrids"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\Site"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>count<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Site_Num"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"TEXT"</SPAN><SPAN class="punctuation token">)</SPAN>
countexp <SPAN class="operator token">=</SPAN> count
arcpy<SPAN class="punctuation token">.</SPAN>CalculateField_management<SPAN class="punctuation token">(</SPAN>Output_Location <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\MapGrids"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\Site"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>count<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Site_Num"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"'"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>countexp<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"PYTHON_9.3"</SPAN><SPAN class="punctuation token">)</SPAN>
count <SPAN class="operator token">=</SPAN> count <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>