Using ArcMap 10.6, I've tried the following code from a previous post and get an error or it executes but does nothing. Here is the code and error I receive:
Code
mxd = arcpy.mapping.MapDocument ("CURRENT")
df = arcpy.mapping.ListDataFrames (mxd, "Layers") [0]
for lyr in arcpy.mapping.ListLayers (mxd,"", df):
lyr.transparency = 0
arcpy.RefreshActiveView()
mxd.save
del mxd
Error
RuntimeError: LayerObject: Set attribute transparency does not exist
1 Answer 1
As was mentioned by @Michael Stimson, not all layers support transparency.
From the documentation:
Not all layers support the transparency property (for example, fabric group layers and web service sublayers), so it is good practice to test for this ahead of time using the supports method.
So, your code could look like this:
mxd = arcpy.mapping.MapDocument ("CURRENT")
df = arcpy.mapping.ListDataFrames (mxd, "Layers") [0]
for lyr in arcpy.mapping.ListLayers (mxd,"", df):
if lyr.supports("TRANSPARENCY"):
lyr.transparency = 0
arcpy.RefreshActiveView()
mxd.save
del mxd
One other thing to check is that your data frame is actually called "Layers". If not, the code won't do anything.
It's also important to know that 0 means the layer is not transparent, but 100 means the layer is completely transparent.
Explore related questions
See similar questions with these tags.
lyr.name
before trying to change its transparency to see which layer gives you the error. Also, please always provide the full error message including its line number. When refering to any previous post please always include a link to it.