0

I am trying to copy feature layers using the following code, but get no results. Can anyone help me understand why the code does not work?

import os
import arcpy 
arcpy.env.workspace = ws = 'C:\\WorkSpace\\sahie_saipe\\sahie_saipe.gdb'
dictionary_Layer = {'co06_Layer':'co06', 'co07_Layer':'co07', 'cnty08_Layer':'co08', 'co09_Layer':'co09', 'co10_Layer':'co10', 'co11_Layer':'co11', 'co12_Layer':'co12', 'st_Select':'state'}
for layer in arcpy.mapping.ListLayers(mxd):
    if layer in dictionary_Layer:
        old = os.path.join(ws, layer)
        new = os.path.join(ws, dictionary_Layer[layer])
        try:
            arcpy.CopyFeatures_management(old,new,"")
            print 'copy %s to %s' %(layer, dictionary_Layer[layer])
        except:
            print 'Could not copy %s' 
2

Instead of using arcpy.mapping.ListLayers try using arcpy.ListFeatureClasses. It will go off of the workspace, which you are already setting, and I have found it pretty easy to use.

See more information HERE

0

If this is the full code then I believe the code is failing as where do you specify the mxd variable? The ListLayers function takes a map document object.

  • Thanks for your response. I have corrected the 'mxd' issue and still get no results! – mersh Jul 29 '14 at 14:22

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.