2

My project starts from a MXD containing Query Layers. I have to prepare the data in this "MasterMXD" for use in an offline application. Working with ArcMap 10.2.1 for this project. My Python script follows a simple structure:

  • Loop over all layers in the MasterMXD.
  • MakeFeatureLayer from the Query layer.
  • FeatureClassToFeatureClass to store feature layer as a feature class.
  • Continue from there to CreateRuntimeContent later in the script.

Here is part of my Python script:

for df in arcpy.mapping.ListDataFrames(master_mxd):
   for lyr in arcpy.mapping.ListLayers(master_mxd, data_frame = df):
      lyrName = lyr.name.encode("ascii", "ignore")
      lyrName = lyrName.replace(" ", "")
      featureLyr = arcpy.MakeFeatureLayer_management(lyr, lyrName)
      arcpy.FeatureClassToFeatureClass_conversion(featureLyr, outFolder, lyrName)

The problem I am facing is that some of the layers in the MXD pass through the script without problem, while others give an error 000229:

ERROR 000229: cannot open GPL0 for the MakeFeatureLayer_management tool.

It is always the same layers that give the error.

I cannot see any differences between layers that give this error and the layers that do not give it. I did not construct the database that serves the query layers and cannot find any 'GPL0' anywhere. I'm puzzled!

Does anyone have an idea what is causing this ERROR 000229 showing up for some of my query layers in the MakeFeatureLayer_management tool?

2
  • 1
    Also, and this may be incidental since you stated your code works part of the time, but I've always used .getOutput(0) or simply a call by index [0] on MFL to return the layer result: featureLyr = arcpy.MakeFeatureLayer_management(lyr, lyrName)[0] Commented Feb 23, 2017 at 0:56
  • Thanks guys. Midavalo, skipping the MakeFeatureLayer line worked. I thought I would not be able to use a query layer in the FeatureClassToFeatureClass.
    – Wout
    Commented Feb 28, 2017 at 8:17

1 Answer 1

1

Take a look at What is a query layer?:

Query Layers behave like any other feature layer or stand-alone table, so they can be used to display data, used as input into a geoprocessing tool, or accessed programmatically using developer APIs.

That is why using it directly (as input parameter) in Feature Class to Feature Class worked (as suggested by Midavalo).

for df in arcpy.mapping.ListDataFrames(master_mxd):
   for lyr in arcpy.mapping.ListLayers(master_mxd, data_frame = df):
      lyrName = lyr.name.encode("ascii", "ignore")
      lyrName = lyrName.replace(" ", "")
      arcpy.FeatureClassToFeatureClass_conversion(lyr, outFolder, lyrName)

About the ArcPy Error 000229: Cannot open <value>, this article lists possible causes:

  • The data is inaccessible, unavailable, or invalid.
  • There are unsupported data types in 64-bit background processing.
  • Unsupported tools are unable to run in background processing.
  • The 64-bit background geoprocessing does not have the necessary 64-bit libraries.

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.