count = 0      while count < 10:          Output_polyline =  os.path.join(savepath  + "\\Results.gdb"  + "\\LCP_" + str(count))         End_Raster =  os.path.join(savepath  + "\\Scratch.gdb"  + "\\End_Raster_" + str(count))          #Raster to Polyline         arcpy.AddMessage("Saving Least Cost Path {0}..." .format(count + 1))         arcpy.RasterToPolyline_conversion(get_LCP(count), Output_polyline, "ZERO", "0", "SIMPLIFY", "")              # List line feature classes in Results.gdb         fclist = arcpy.ListFeatureClasses("*","Line",savepath  + "\\Results.gdb")         for fc in fclist:             lcpcount = arcpy.GetCount_management(fc)              if lcpcount == 0:                 break
					
				
			
			
				
			
			
				Solved! Go to Solution.
#Raster to Polyline arcpy.AddMessage("Saving Least Cost Path {0}..." .format(count + 1)) try:     arcpy.RasterToPolyline_conversion(get_LCP(count), Output_polyline, "ZERO", "0", "SIMPLIFY", "") except:     arcpy.AddMessage("Empty feature class")     breaklcpcount = arcpy.GetCount_management(fc)
lcpcount = int(arcpy.GetCount_management(fc).getOutput(0))
count = 0
while count < 10:
    Output_polyline =  os.path.join(savepath  + "\\Results.gdb"  + "\\LCP_" + str(count))
    End_Raster =  os.path.join(savepath  + "\\Scratch.gdb"  + "\\End_Raster_" + str(count))
    #Raster to Polyline
    arcpy.AddMessage("Saving Least Cost Path {0}..." .format(count + 1))
    arcpy.RasterToPolyline_conversion(get_LCP(count), Output_polyline, "ZERO", "0", "SIMPLIFY", "")
    #check to see if the new Output_polyline is empty, and break if so:
    if int(arcpy.management.GetCount(Output_polyline).getOutput(0)) == 0:
        #you could also delete the empty feature class if you want
        #arcpy.management.Delete(Output_polyline)
        break
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
count = 0
while count < 10:
    Output_polyline =  os.path.join(savepath  + "\\Results.gdb"  + "\\LCP_" + str(count))
    End_Raster =  os.path.join(savepath  + "\\Scratch.gdb"  + "\\End_Raster_" + str(count))
    #Raster to Polyline
    arcpy.AddMessage("Saving Least Cost Path {0}..." .format(count + 1))
    arcpy.RasterToPolyline_conversion(get_LCP(count), Output_polyline, "ZERO", "0", "SIMPLIFY", "")
    #check to see if the new Output_polyline is empty, and break if so:
    if int(arcpy.management.GetCount(Output_polyline).getOutput(0)) == 0:
        #you could also delete the empty feature class if you want
        #arcpy.management.Delete(Output_polyline)
        break
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		#Raster to Polyline arcpy.AddMessage("Saving Least Cost Path {0}..." .format(count + 1)) try:     arcpy.RasterToPolyline_conversion(get_LCP(count), Output_polyline, "ZERO", "0", "SIMPLIFY", "") except:     arcpy.AddMessage("Empty feature class")     break