I am having a bit of trouble with Python. I am trying to create a script (hard-coded for now, but eventually soft-coded to make a script tool) that allows the user to back up layers of a given map in ArcGIS Pro by creating local feature classes in a new file geodatabase named with today's date. Here is my script:
import arcpy arcpy.env.overwriteOutput = True Project = r"P:\Projects\MyProject.aprx"outPath = r"P:\Projects" myProj = arcpy.mp.ArcGISProject(Project) myMap = myProj.listMaps("Map") today = datetime.date.today() date = today.strftime("%Y%m%d") name = "Backup_" + str(date) + ".gdb" arcpy.CreateFileGDB_management(outPath, name) GDB = outPath + "\\" + name for layer in myMap.listLayers(): arcpy.CopyFeatures_management(layer,GDB)
My script keeps failing in the Python console, and I get the message: "arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 000840: The value is not a Feature Layer. Failed to execute (CopyFeatures)."
My understanding is that listLayers creates a layer object, but to use Copy Features I need a feature layer. I've tried re-writing the 'for' loop to make a feature layer as follows:
for layer in myMap.listLayers(): Feat = arcpy.MakeFeatureLayer_management(layer,"Templayer") arcpy.CopyFeatures_management(Feat,GDB)
However, I get the same error.
My layers are all web-hosted, although I don't know if this is the cause of my problem. I really want a script that allows me to select a map within ArcGIS Pro, loop through all layers in the map, and copy them into a new FGDB.
How can I get my script to work?
Is there a way to convert a layer object into a feature layer?
Am I using the wrong approach?