0

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

9
  • error 99999 is a very generic issue. but your g:drive has {} (odd characters)
    – Mapperz
    Commented Feb 11, 2019 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
    Commented Feb 11, 2019 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. Commented Feb 11, 2019 at 16:42
  • 1
    What if you move the script back to its old position? Does it work again? If not, your datasets and folders might have changed and you did not realize it. Otherwise, just few thoughts: 1) avoid using pathnames with spaces inside; 2) try putting r in front of all your paths in your script (e.g. Export = r"G:\zn\NM\GGB\Applicaties-Admin\Kerngis\ExpImp\{}\Export_{}.gdb\Mask".format(Project_number, Project_number)); 3) if you can, specify your paths with os.path; 4) Last but not least: chek if everything (files and folders) exist!
    – umbe1987
    Commented Feb 14, 2019 at 16:19
  • 1
    5) try to re-build tour script step-by-step (e.g. start with explicit paths, dataframe names, layer names, so on)
    – umbe1987
    Commented Feb 14, 2019 at 16:25

2 Answers 2

1

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)
1
  • I have followed your advice and I have added the .format, however it still comes back with the same error.
    – Remko
    Commented Feb 13, 2019 at 9:32
1

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)
3
  • 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
    Commented Feb 14, 2019 at 10:02
  • What is the error you get after using my suggestions? Is it the same as before or different?
    – umbe1987
    Commented Feb 14, 2019 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
    Commented Feb 14, 2019 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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