2

I'm trying to export ALL layers from the table of contents from a map document but I get the following error:

Runtime error Traceback (most recent call last): File "", line 14, in File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 2434, in CopyFeatures raise e ExecuteError: ERROR 000210: Cannot create output C:\Users\jnmiller\Desktop\Global_Map.mxd\New_Shapefile.shp Failed to execute (CopyFeatures).

Python Code:

import os, arcpy

infolder = "‪C:\Users\jnmiller\Desktop\Global_Map.mxd"
outfolder = "C:\EnterpriseFolder\NEO"
#Get name of vector layers in the TOC
mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
layers = [f.name for f in arcpy.mapping.ListLayers(mxd, "*", df) if         
f.isFeatureLayer]


for layer in layers:
    #Join output infolder to layer name and append .shp
    outfolder = os.path.join(infolder, "{}.shp".format(layer))
    arcpy.CopyFeatures_management(layer, outfolder)
3

With this:

for layer in layers:
    #Join output infolder to layer name and append .shp
    outfolder = os.path.join(infolder, "{}.shp".format(layer))
    arcpy.CopyFeatures_management(layer, outfolder)

You are trying to copy the features to

C:\Users\jnmiller\Desktop\Global_Map.mxd

Which is not a folder.

I Think this is what you want:

for layer in layers:
    #Join output infolder to layer name and append .shp
    arcpy.CopyFeatures_management(layer, os.path.join(outfolder,"{}.shp".format(layer)))
  • I tried that but I received the following error for the CopyFeatures_Management: Parsing error SyntaxError: invalid syntax (line 13) – Jordan Aug 31 '17 at 14:14
  • Add another paranthesis ) – BERA Aug 31 '17 at 14:20
  • How to export Annotation feature class in case I am using FGDB?? – GIS Data Butcher Nov 20 '17 at 5:42
  • Dont know which tool to use. Post a new question – BERA Nov 20 '17 at 6:35
0

I think you should change the following sentence: outfolder = os.path.join(infolder, "{}.shp".format(layer)

  1. Are you sure infoder is really a folder ?
  2. The shapefile mayby wrong.It should be like "{0}.shp".format(layer) I hope this can help you !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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