I am trying to create a python scrip to batch erase shapefiles. I have created a script that works, however, I know there is a better way and I just am not good enough at scripting to figure it out. I want to create a loop to allow the script to just to go through the folders and just erase the new shapefile from the old to see change. The way I have it now I have to update about 16 path names. Also, the the script will send me an error if there is nothing to erase. I know this requires an if statement but again, I am just now knowledgeable enough to figure it out. Below, is the scrip that works and hopefully it will give and idea of what it is I am trying to achieve.
import arcpy #Set workspace arcpy.env.workspace = "USER_TEMP\\RAY\\test\\" #Erase workspace erase_ADE01 = "\\ADE01_ALL_BUFFERS_05_09_16.shp" erase_COF01 = "\\COF01_ALL_BUFFERS_05_09_16.shp" erase_CVI04 = "\\CVI04_ALL_BUFFERS_05_09_16.shp" #Current buffers workspace current_ADE01 = "\\ADE01_ALL_BUFFERS_TEST.shp" current_COF01 = "\\COF01_ALL_BUFFERS_TEST.shp" current_CVI04 = "\\CVI04_ALL_BUFFERS_TEST.shp" #Outputworkspace output = "\\test\\delta_test\\" #Erase tool; NEED HELP-WHEN THERE IS NOTHING TO ERASE SCRIPT FAILS arcpy.ET_GPErase(current_ADE01, erase_ADE01, output + "ADE01_ALL_DELTAS_TEST.shp", 0.0) arcpy.ET_GPErase(current_COF01, erase_COF01, output + "COF01_ALL_DELTAS_TEST.shp", 0.0) arcpy.ET_GPErase(current_CVI04, erase_CVI04, output + "CVI04_ALL_DELTAS_TEST.shp", 0.0) print "Script completed"
So, I don't know why I didn't think of this before but what I did was merge the erase features together so that way there is only one feature to erase from. Then I just threw it in a "for loop" and everything works well for that part. Now I am still getting that error for when there is nothing to erase (the features are the same). How would I write an if statement for this:
#Erase tool; NEED HEELP-WHEN THERE IS NOTHING TO ERASE SCRIPT FAILS for fc in arcpy.ListFeatureClasses(): erase_feature = "\\all_erase.shp" #this is the merged feature erase_output = "\\test\\delta_test\\" + "_ALL_DELTAS_TEST.shp" arcpy.ET_GPErase(fc, erase_feature, erase_output, 0.0)
So, I am getting closer to figuring this out. My script will run all the way to the end now. However, it wasn't erasing because of memory issues. So i upgraded to python64x. Here is my script:
for fc in arcpy.ListFeatureClasses(): prefix = fc[:6] erase_output = "\\test\\delta_test\\" + prefix + "_ALL_DELTAS_TEST.shp" try: arcpy.ET_GPErase(fc, merge_output, erase_output, 0.0) except arcpy.ExecuteError: print arcpy.GetMessages(2) print "Erase for " + prefix + " unsuccessful" except: print "There has been a non-tool error"
The "There has been a non-tool error" print pops up now that I have downloaded the different pywin. Before I did that, the error was in the first except because of the memory issues. What am I doing wrong?