Hi, to load the layers to the mxd wasn't that hard. But instead of altering the code for each of the 20 (i recounted them:cool:) and dispatch them all one by one, i thought it should be possible to nest them. The result is the following code. First the nice thing about: the script worked totally through, all the 20. "dones" were printed.But when i opened afterwards the mxd i realised, that just the symbology of sourceLayer1 and sourceLayer2 were adapted. Do you see the fault or problem? # ---------------------------------------------------------------------------
# iteration durch raster_und symbol.py
# Created on: 2012-12-31 01:39:43.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------
import arcpy
#Specifies mxd
mxd = arcpy.mapping.MapDocument(r"H:/Desktop/Masterarbeit/test/Besprechung_Crap Ses.mxd")
#Specifies dataframe of interest
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
#Specifies layer file with the symbology you want to apply to the other raster layers
sourceLayer1 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_95CI.lyr")
sourceLayer2 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_95CI_diff.lyr")
sourceLayer3 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_mean.lyr")
sourceLayer4 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\E_mean_diff.lyr")
sourceLayer5 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_depos_diff.lyr")
sourceLayer6 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_deposited.lyr")
sourceLayer7 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_pass_diff.lyr")
sourceLayer8 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_passages.lyr")
sourceLayer9 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Nr_tree_impacts.lyr")
sourceLayer10 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_95CI.lyr")
sourceLayer11 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_95CI_diff.lyr")
sourceLayer12 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_mean.lyr")
sourceLayer13 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Ph_mean_diff.lyr")
sourceLayer14 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Reach Probability [%].lyr")
sourceLayer15 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Reach_prob_diff.lyr")
sourceLayer16 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Rvol.lyr")
sourceLayer17 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Rvol_diff.lyr")
sourceLayer18 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Tree_impact_heights .lyr")
sourceLayer19 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Vmax.lyr")
sourceLayer20 = arcpy.mapping.Layer(r"H:\Desktop\Masterarbeit\test\RESULTATE\lyr_files_neu\Vmax_diff.lyr")
#Loops through layers in the first data frame in your mxd and
#creates a list of Layers starting with Reach_probability:
for lyr in arcpy.mapping.ListLayers(mxd, "E_95CI", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer1)
print "done_ 1"
for lyr in arcpy.mapping.ListLayers(mxd, "E_95CI_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer2)
#Saves mxd
mxd.save()
print "done_2"
for lyr in arcpy.mapping.ListLayers(mxd, "E_mean", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer3)
print "done_3"
for lyr in arcpy.mapping.ListLayers(mxd, "E_mean_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer4)
#Saves mxd
mxd.save()
print "done_4"
for lyr in arcpy.mapping.ListLayers(mxd, "Nr_depos_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer5)
print "done_5"
for lyr in arcpy.mapping.ListLayers(mxd, "Nr_deposited", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer6)
#Saves mxd
mxd.save()
print "done_6"
for lyr in arcpy.mapping.ListLayers(mxd, "Nr_pass_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer7)
print "done_7"
for lyr in arcpy.mapping.ListLayers(mxd, "Nr_passages", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer8)
#Saves mxd
mxd.save()
print "done_8"
for lyr in arcpy.mapping.ListLayers(mxd, "Nr_tree_impacts*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer9)
print "done_9"
for lyr in arcpy.mapping.ListLayers(mxd, "Ph_95CI", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer10)
#Saves mxd
mxd.save()
print "done_10"
for lyr in arcpy.mapping.ListLayers(mxd, "Ph_95CI_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer11)
print "done_11"
for lyr in arcpy.mapping.ListLayers(mxd, "Ph_mean", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer12)
#Saves mxd
mxd.save()
print "done_12"
for lyr in arcpy.mapping.ListLayers(mxd, "Ph_mean_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer13)
print "done_13"
for lyr in arcpy.mapping.ListLayers(mxd, "Reach Probability [%]*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer14)
#Saves mxd
mxd.save()
print "done_14"
for lyr in arcpy.mapping.ListLayers(mxd, "Reach_prob_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer15)
print "done_15"
for lyr in arcpy.mapping.ListLayers(mxd, "Rvol", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer16)
#Saves mxd
mxd.save()
print "done_15"
for lyr in arcpy.mapping.ListLayers(mxd, "Rvol_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer17)
print "done_17"
for lyr in arcpy.mapping.ListLayers(mxd, "Tree_impact_heights *", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer18)
#Saves mxd
mxd.save()
print "done_18"
for lyr in arcpy.mapping.ListLayers(mxd, "Vmax", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer19)
print "done_19"
for lyr in arcpy.mapping.ListLayers(mxd, "Vmax_diff*", df):
#Determines if layer is a raster layer and applies lyr symbology if it is
if lyr.isRasterLayer:
arcpy.ApplySymbologyFromLayer_management(lyr, sourceLayer20)
#Saves mxd
mxd.save()
print "done_ 20! :D ! "
#Deletes the reference to the mxd from memory (not the actual mxd file)
del mxd
In the "search function", i had intentionally dropped the * within the "E_95CI", because the layers are called exactly like this and there are other layers called E_95CI_diff_... .Suggestions are welcome. Also for the walk function, I arranged more a workaround (with a long typing code..) than to delve into the walk-function...