0

I would like to export all layers within an .aprx to a .gdb.

This is the script:


# Set the .aprx file as the workspace
aprx = arcpy.mp.ArcGISProject(r"B:\XXX000\XXX35219_BCG\Workspaces\EIAR\Chapter 7 - Air Quality\Chapter 7 - Air Quality.aprx")

# Set the output workspace to the .gdb file
arcpy.env.scratchWorkspace = r"B:\XXX000\XXX35219_ABC\Workspaces\EIAR\Chapter 7 - Air Quality\Default.gdb"

# Get a list of all the data in the .aprx file
data_list = aprx.listTables() + aprx.listFeatureClasses() + aprx.listRasters()

# Loop through the data list and export each item to the .gdb file
for data in data_list:
    arcpy.FeatureClassToGeodatabase_conversion(data, arcpy.env.scratchWorkspace)

print("Export complete")

This is the error that follows:

Traceback (most recent call last): File "", line 10, in AttributeError: 'ArcGISProject' object has no attribute 'listTables'

1 Answer 1

2

There are 2 ways you can list tables --

  1. ListTables from the workspace
arcpy.env.workspace = "path to fGDB"
arcpy.ListTables()
  1. listTables from the map object
aprx = arcpy.mp.ArcGISProject(r"B:\XXX000\XXX35219_BCG\Workspaces\EIAR\Chapter 7 - Air Quality\Chapter 7 - Air Quality.aprx")
m = aprx.listMaps()[0] # Will use the first map it finds in the project
m.listTables()

Your code is attempting to list tables on the Project (aprx), which does not have a List Tables function.

You'll need to have a 2nd look at your aprx.listFeatureClasses() + aprx.listRasters() bit of code as well. I know these don't exist off the aprx, however they may have their own answer as to where to find them which is different than the tables.

After that, you're trying to take a list of many different things (tables, feature classes, rasters) and use the FeatureClass to Geodatabase tool to copy them. I hope you see how throwing a raster into the feature class tool is going to fail. You aren't going to accomplish what you want with a single, simple bit of code.

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.