Hello Ken,I think the main problem here is the expectation of what you'd get with the functions upper/lower. So I'll demonstrate with IDLE:>>> someText = 'IamAlayer' >>> print someText.upper() IAMALAYER >>> print someText.lower() iamalayer >>>
As you can see, the function 'lower' returns all lower case; the function 'upper' returns all upper case. It is that cut and dried.So the only way your 'if' statement to be true as you need it to be to execute the 'removeLayer' part of the code, you at least need to feed in the proper conditional variables...So you could go with 'lower' as you had the code originally - which for the layer in question would return 'dams' (if there is such a layer in the map's data frame), so you'd need to set the 'layer_name' variable to the following (not with the 1st letter capitalized):layer_name = r'dams'extra clarification:As further explanation by example, it doesn't matter whether you use 'upper' or 'lower', you cannot use mixed case on the variable 'layer_name'....you should define it as either 'dams' (lower) or 'DAMS' (upper) as shown:>>> if layer_name.lower() == 'dams': print 'yes, we have a match - go ahead with the rest code block.' yes, we have a match - go ahead with the rest code block. >>> if layer_name.upper() == 'DAMS': print 'yes, we have a match - again, proceed...' yes, we have a match - again, proceed... >>> if layer_name.lower() == 'Dams': print 'go go go proceed with the code block...' else: print 'no way....we do not agree - halt this block!' no way....we do not agree - halt this block! >>> >>> if layer_name.upper() == 'Dams': print 'go go go proceed with the code block...' else: print 'no way....we do not agree - halt this block!' no way....we do not agree - halt this block! >>>
At any rate, on your 'if' statement, the condition lyr.name.upper() == r'DAMS' [or lyr.name.lower() == r'dams'] must be met for 'arcpy.mapping.RemoveLayer(df, lyr)' to execute...If you have any questions about that, let me know. Also, you will need to save the mxd (whether you use 'mxd.save()' or 'mxd.saveACopy(...)', it doesn't matter, you must save the mxd for any changes to persist.Enjoy,Wayne