Looping Select by Attribute, ADDING one by one feature each time, and run a tool

Discussion created by rafaelruas on Mar 26, 2014
Latest reply on Jan 10, 2017 by dkwiens
I am new w/ ArcPy! I am having some dificulties to create a simple workflow to create an "Accumulative Curve":
1) A point feature class as input;
2) Select the first 3 points based on a table field (ObjectID, for exe.);
3) Apply Minumun Boundary Geometry tool w/ Convex_Hull option, on those selected points;
4) Add a field on the output and calculate shape area in hectares;
5) Write a txt file, w/ two coluns: n. of selected points and Shape Area value;

At this point OK as you can see in the script above.
From now, I have no idea how to integrate LOOP and SELECT!!!

6) Select the first 3 points as step 2, and ADD the fourth feature on the selection;
7) Repeat steps 3, 4, and 5.
8) ADD the fifth feature on selection;
9) Repeat steps 3, 4, and 5.

As you can see, I´d like to have a TXT file, w/ two coluns, the first one to show the number of selected points and the another one to show area value, in hectares!!!

That´s what I could do!!!!

# Import arcpy module and set the current workspace
# Set the overwriteOutput environment setting to True
import arcpy
arcpy.env.workspace = r"C:/TESTE_py/AccumCurve.gdb"
arcpy.env.overwriteOutput = True

# Create a inputFC feature layer
arcpy.MakeFeatureLayer_management ("Bandaid", "Bandaid_lyr")

# Select the first 3 points based on OBJECTID field values
SQLExp = '"OBJECTID" IN (1,2,3)'
selected = arcpy.SelectLayerByAttribute_management ("Bandaid_lyr", "NEW_SELECTION", SQLExp)

# Get count the number of selected points
count = arcpy.GetCount_management (selected)
print str(count) + " points"

# Execute Minimum Bounding Geometry Tool (Convex Hull) over selection
arcpy.MinimumBoundingGeometry_management ("Bandaid_lyr","MCP_3", "CONVEX_HULL")

# Add field and calculate area (hectares)
arcpy.AddField_management ("MCP_3", "HECTARES", "Float")

with arcpy.da.UpdateCursor ("MCP_3", ["Shape_Area", "HECTARES"]) as cursor:
    for row in cursor:
        geom = row[0]
        row[1] = geom / 10000

# Read and create a variable w/ the area value from MCP_3 feature class
fc = r"C:/TESTE_py/AccumCurve.gdb/MCP_3"
field = "HECTARES"
rows = arcpy.SearchCursor(fc)
for row in rows:
    area_value = (row.getValue(field))
    print str(area_value) + " hectares"
# Write a TXT file, w/ 2 colunms: n. of points (count) and hectares
txtFile = open("C:/TESTE_py/MCP_3.txt", "w")
txtFile.write("Count ; Area_Value" + "\n")
line = "{0} ; {1}".format (count, area_value)

# Close the text file

print "Script completed"

Tks for some help!!!