The part of the script I'm having trouble with is the arcpy.SearchCursor. The cursor runs 1x and then does not re-run. The goal was to re-retrieve the field value and apply it to the image layout. It works on the first run but then applys the same value to every image layout after. The SQL query I'm using limits the records to 1 record, but I was hoping it would re-run and apply the new SQL query.
x = 1 while x <= formatted_rand_ct: row_rand = random.randint(0,record_count) sqlExp = new_name + "=" + str(row_rand) rows = arcpy.SearchCursor(newlayer, sqlExp) for row in rows: l = row.getValue(field_label) arcpy.SelectLayerByAttribute_management(newlayer, "NEW_SELECTION", sqlExp) df.zoomToSelectedFeatures() if desc.shapeType == "Point": df.scale = scale if desc.shapeType == "Point" or desc.shapeType == "Polygon": elm = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT") elm.text = str(field) + " " + str(row_rand) elm2 = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT") elm2.text = str(l) arcpy.mapping.ExportToJPEG(mxd, output + str(row_rand)) arcpy.RefreshActiveView() arcpy.AddMessage("Finished Export of Image: OBJECTID" + " " + str(row_rand)) x += 1 else: arcpy.AddMessage("Points or Polygons Only") break del mxd arcpy.AddMessage("\nDone!\n")