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

Fezter
22k11 gold badges72 silver badges128 bronze badges
asked Mar 14, 2018 at 22:36
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 Commented Mar 14, 2018 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. Commented Mar 14, 2018 at 23:04

1 Answer 1

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.

answered Mar 14, 2018 at 23:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.