2

I have a large script that does many things, but at the end it creates a buffer whose output is an existing feature class that is overwritten. That feature class is the data source for a layer that is in a mxd that is current an object in memory. For some reason, that layer from the mxd is being removed as soon as I run the buffer. I isolated the problem with the code below by saving out two mxds. When I open the 1st mxd has the layer in the TOC, but in the 2nd mxd it is gone.

sqlWellName = "NAME = " + "'" + WELL_NAME + "'"
SDE_lyr = "SDElyr"
arcpy.MakeFeatureLayer_management(r"C:\GDB_Connect\Editor\MAIN@DEFAULT.sde\WATER.WELLS", SDE_lyr)
arcpy.SelectLayerByAttribute_management(SDE_lyr, "NEW_SELECTION", sqlWellName)
mxd.saveACopy("C:\ProjectData\Map_1.mxd")
arcpy.Buffer_analysis(in_features=SDE_lyr, out_feature_class=r"C:\ProjectData\DATA\AutoMap.gdb\Buffer1Mile", buffer_distance_or_field="1 Miles", line_side="FULL", line_end_type="ROUND", dissolve_option="NONE", dissolve_field="", method="PLANAR")
newmxd.saveACopy("C:\ProjectData\Map_2.mxd")

Is this a bug?

  • I have seen this issue with other tools. In my case, I changed the layer name and it stopped removing it. In your case I am not sure it will work. Change your workspace to scratchGDB – Ben S Nadler Nov 6 '17 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.