Arcpy – Resolving ERROR 000732: Dataset Does Not Exist in ArcGIS 10.8

arcgis-10.8arcmaparcpyerror-000732python-2.7

My main goal is to export a layer from ArcMap as a shapefile and upload it to AGOL. However, I am stuck at this intersection.

All my scripts work in the python console within ArcMap. However, I cannot run the following as a stand-alone script.

#!python2

import os
import arcpy

# Change Directory
os.chdir(r'C:\ \ \ \ArcGIS\Exports')

# Export Layer Data
arcpy.mapping.MapDocument(r"P:\ \ \*2021.mxd")
analysis = arcpy.CopyFeatures_management('Splice Point', r'C:\ \ \ \ArcGIS\Exports\itemSplice.shp')
print(analysis)

Here is the error I get:
ERROR 000732: Input Features: Dataset Splice Point does not exist or is not supported
Failed to execute (CopyFeatures).

It is worth noting that when I run the following code:

import os
import arcpy

mxd = arcpy.mapping.MapDocument(r"P:\ \ \*2021.mxd")
analysis = arcpy.mapping.ListLayers(mxd, None, None)

print(analysis)

I get a list of layers within the .mxd. One of the listed layers (the one I want), matches the layer mentioned in "CopyFeatures_management."

Best Answer

You were almost there...you need to select the layer from the map document and then use that as the source for the CopyFeatures. e.g.

# Export Layer Data
arcpy.mapping.MapDocument(r"P:\ \ \*2021.mxd")

# this selects the first item from the ListLayers result object that has a name
# matching "Splice Point".
analysis = arcpy.mapping.ListLayers(mxd, "Splice Point", None)[0] 

arcpy.CopyFeatures_management(analysis, r'C:\ \ \ \ArcGIS\Exports\itemSplice.shp')
Related Question