1

I've made an arcpy script which worked last week, but I placed it somewhere different on my computer. I've made sure all the source files etc. are connected. However now I keep getting an error message when it comes to the erase function, it comes up with the following error:

Traceback (most recent call last):
  File "G:\zn\NM\GGB\Applicaties-Admin\Kerngis\ExpImp\Base data\Scripts\List mxd.py", line 22, in <module>
    arcpy.Erase_analysis (lyr, Export, Import)
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\analysis.py", line 176, in Erase
    raise e
ExecuteError: ERROR 999999: Error executing function.
The table was not found.
The table was not found. [Kabel_en_leiding_lijnen_Erased]
The table was not found.
The table was not found. [Kabel_en_leiding_lijnen_Erased]
The operation was attempted on an empty geometry.
Failed to execute (Erase).


Failed to execute (Import)

My script is the following:

import arcpy
import arcpy.mapping

Project_number = arcpy.GetParameterAsText(0)

arcpy.env.overwriteOutput = True

mxd = arcpy.mapping.MapDocument("G:\\zn\\NM\\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\{}.mxd".format(Project_number, Project_number))  # Uses your currently open MXD
for df in arcpy.mapping.ListDataFrames(mxd, ''): # Loop through dataframes
    for lyr in arcpy.mapping.ListLayers(mxd, '', df): # Loop through layers

        # Any tools you want to run on each layer go here


        Export = "G:\\zn\\NM\\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Export_{}.gdb\\Mask".format(Project_number, Project_number)
        Import = "G:\\zn\\NM\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Import_{}.gdb\\{}_Erased"(Project_number, Project_number, lyr)
        NewFile = "G:\\zn\\NM\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Import_{}.gdb\\{}_MultipartToSing".format(Project_number, Project_number, lyr)
        Merge = "G:\\zn\\NM\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Import_{}.gdb\\{}_Merged".format(Project_number, Project_number, lyr)


        arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", Export, "", "NEW_SELECTION", "NOT_INVERT")
        arcpy.Erase_analysis (lyr, Export, Import)
        arcpy.DeleteFeatures_management (lyr)
        arcpy.Append_management(Import, lyr, "NO_TEST")
        arcpy.Append_management(NewFile, lyr, "NO_TEST")

I have also tried running these same steps in modelbuilder, to see if it was the script or if something else was going on. The same error occurs, the image below will display my model.Model

I cannot figure out for the life of me why it is giving me errors. The feature class being used is a line feature class, not sure if that makes a difference.

I am using ArcGIS 10.3.1

  • error 99999 is a very generic issue. but your g:drive has {} (odd characters) – Mapperz Feb 11 at 14:44
  • 1
    If arcpy says it doesn't exist, you should entertain the possibility that it doesn't. What do print and arcpy.Exists() have to say? – Vince Feb 11 at 16:02
  • 1
    I think I get that error when the erase (and other) tool runs out of memory due to very large feature class. – Emil Brundage Feb 11 at 16:42
  • If there's a chance your feature class is very large have you tried running your code on a subset of it? – PolyGeo Feb 11 at 19:50
  • You may consider referencing the data explicitly rather than using the mapping module to reference layers in a .mxd file. You can add your results to the .mxd later. – Chris Feb 11 at 22:01
0

Your definition of Import doesn't have .format after the string. It's not finding the table you're trying to set to Import because it's not formatting in the other variables into the path.

Your culprit line:

    Import = "G:\\zn\\NM\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Import_{}.gdb\\{}_Erased"(Project_number, Project_number, lyr)

Needs to be:

    Import = "G:\\zn\\NM\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Import_{}.gdb\\{}_Erased".format(Project_number, Project_number, lyr)
  • I have followed your advice and I have added the .format, however it still comes back with the same error. – Remko Feb 13 at 9:32
0

Just a guess. arcpy.mapping.ListLayers returns a list of Layer objects, so in your for loop, try to put lyr.name or lyr.datasetName in a .format method.

Try to change (e.g.):

Import = "G:\\zn\\NM\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Import_{}.gdb\\{}_Erased"(Project_number, Project_number, lyr)
NewFile = "G:\\zn\\NM\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Import_{}.gdb\\{}_MultipartToSing".format(Project_number, Project_number, lyr)
Merge = "G:\\zn\\NM\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Import_{}.gdb\\{}_Merged".format(Project_number, Project_number, lyr)

into something like (also added the missing .format to Import variable as @flintlockspecial pointed out):

Import = "G:\\zn\\NM\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Import_{}.gdb\\{}_Erased".format(Project_number, Project_number, lyr.name)
NewFile = "G:\\zn\\NM\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Import_{}.gdb\\{}_MultipartToSing".format(Project_number, Project_number, lyr.name)
Merge = "G:\\zn\\NM\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Import_{}.gdb\\{}_Merged".format(Project_number, Project_number, lyr.name)
  • Sadly this wasn't the solution either. In my search for answers I've tried a modelbuilder approach (need more manual input), to see if it was my script or if something else is going wrong. I've added the model to the orginal post, the same error occurs. – Remko Feb 14 at 10:02
  • What is the error you get after using my suggestions? Is it the same as before or different? – umbe1987 Feb 14 at 10:07
  • It is still the same as before, the only thing that has changed is that it takes a while longer now before the error occurs. – Remko Feb 14 at 10:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.