Basically, I'm bringing layers into arcmap,repairing the data sourc, and then saving out the layers manually so that the new source is saved. This is very time consuming because I have several hundred layers. Repairing the data sources is fairly easy but saving each layer to disk is timely. I have also been overwriting the previous layer file to keep the name the same. Lastly, the alias name does not match the layer name, so I can't use lyr.saveACopy because that uses the alias name.

I've tried:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
    for lyr in arcpy.mapping.ListLayers(mxd):

but no luck...

  • 3
    What you are trying to do is ambiguous. Are you trying to save the changes to the data sources in the map document, or in a .lyr file? the save() method for layers only works if the layer comes from a .lyr file, not just for any layer in a map document. Per ESRI help: "There is a subtle difference between a layer (.lyr) file and a map layer (a layer in a map document). The save method only works when a variable references a layer file and will not work with a map layer. "
    – DPierce
    Aug 2 '13 at 13:38
  • 2
    By "bringing layers into arcmap" do you mean that you are adding datasets as layers or adding layer files? Perhaps edit your question to describe the manual steps you find time consuming more precisely so we know exactly what you are trying to code.
    – PolyGeo
    Aug 2 '13 at 22:13
  • Yes the indent mistake was only made on SE
    – user21130
    Aug 16 '13 at 16:51

You have an indentation problem by the looks of your code:

Should be:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd): # This line needs to be 'de-dented'
    lyr.save() # this line needs to be indented

Not sure if this was an error created when put up on SE?

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.