0

I am trying to Iterate through my TOC and "Erase" part of the feature layers by using a predefined mask. However I keep getting an error that tells me the "Mask" is either not supported, or does not exist. I can say that the feature exists and that the format is supported, as it does work when I use "Erase" within ArcMap itself. Hence it must be something in my code.

I am a beginner at best when it comes to Arcpy/Python.

I have checked the path and this is correct.

Code:

import arcpy
import arcpy.mapping

Project_number = arcpy.GetParameterAsText(0)
Export = r"G:\\zn\\NM\\GGB\\Applicaties-Admin\\Kerngis\\ExpImp\\{}\\Export_{}\\Mask".format(Project_number, Project_number)
Import = r"G:\zn\NM\GGB\Applicaties-Admin\Kerngis\ExpImp\{}\Import_{}\Erased".format(Project_number, Project_number)


mxd = arcpy.mapping.MapDocument("CURRENT")  # 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

    arcpy.Erase_analysis (lyr, Export, Import)
  • 1
    Your indentation is off. – Vince Jan 30 at 13:20
  • 1
    Also, you don't need the r before the path because you already escaped the backslash using `\\`. – ahmadhanb Jan 30 at 13:22
0

It turns out that I needed to add .gdb inside the path names. This is the current working code:

import arcpy
import arcpy.mapping

Project_number = arcpy.GetParameterAsText(0)
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".format(Project_number, Project_number)


mxd = arcpy.mapping.MapDocument("CURRENT")  # 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

        arcpy.Erase_analysis (lyr, Export, Import)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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