I am trying to create a lyr file for each raster file in a folder. To get exact same display settings I thought I would create a lyr file, then, using arcpy copy-paste it for each file in folder and change the data sources.

The script generates new lyr files but does not change data sources - and gives no error. So, what am I doing wrong?

import arcpy
lyrFile = arcpy.mapping.Layer(r"C:\temp\rst\sample.lyr")
for i in arcpy.ListDatasets(): 

closed as off-topic by PolyGeo Dec 23 '16 at 7:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • What version of ArcGIS do you use? Your code works fine for me. I use 10.2.2. – GISGe Aug 18 '14 at 13:49
  • 10.2.1. GISGe, did it actually generate lyr-s containing different rasters for you? - the code works for me too (no errors) but the outcome is a bunch of lyr-s with different names but same data source. – P.P. Aug 18 '14 at 14:07
  • Yes it did. I run the code from the Python Window in ArcMap and there's a GRID, a bmp and a png in my workspace. Try maybe with ´ListRasters()´ instead of ´ListDatasets()´... – GISGe Aug 18 '14 at 14:16
  • You were right, the code is OK. I just discovered that it didnt work because of unconventional naming of raster files. Thank you for your effort GISGe! – P.P. Aug 18 '14 at 14:40

Browse other questions tagged or ask your own question.