1

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

2
  • 1
    Try testing if the layer supports transparency first resources.arcgis.com/en/help/main/10.2/index.html#/Layer/… if lyr.supports (layer_property): lyr.transparency = 0. Or the crash and burn approach try: lyr.transparency = 0 except: pass – Michael Stimson Mar 14 '18 at 22:44
  • Try printing 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. – PolyGeo Mar 14 '18 at 23:04
4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.