I am trying to create a script that applies a layer style from .lyr file to layers in my table of contents that meet a certain criteria. The criteria being the layer name must contain string of "x".
Edit - This script now works for copying .lyr styles to layers that meet a certain if condition.
mxd = arcpy.mapping.MapDocument("CURRENT")
var1 = #Path to .lyr file
var2 = #Path to .lyr file
for lyr in arcpy.mapping.ListLayers(mxd):
if "TEXT" in lyr.name:
arcpy.ApplySymbologyFromLayer_management(lyr, var1)
print lyr.name + " identified as TEXT"
elif "TEXT2" in lyr.name:
arcpy.ApplySymbologyFromLayer_management(lyr, var2)
print lyr.name + " identified as TEXT2"
else:
print lyr.name + " did not meet the criteria."
layer
is defined, and include the diagnostic output of your script.layer
would target the layers that meet the if condition. I'm trying to have my arcpy script look for"string" in variable
then assign a lyr style to the layers that meet thein
condition.try
block?for
block should be toprint lyr.dataSource
, and the output from that should be part of what you report here.