Skip to content

Instantly share code, notes, and snippets.

@alexfriant
Created January 6, 2016 20:46
Show Gist options
  • Save alexfriant/5277cce92be502e13900 to your computer and use it in GitHub Desktop.
Save alexfriant/5277cce92be502e13900 to your computer and use it in GitHub Desktop.
Change the transparency levels on all layers inside of your current ArcMap MXD document in one fell swoop!
##################################################################################################################
#
# Requirements: You'll need ArcGIS Desktop 10.1 or higher with Python 2.7+
#
# If you want to change Transparency for all the layers in your ArcMap MXD quickly, this will do the trick.
#
# 1. Copy / Paste the initial commands and function definitions below into an MXD's Python command shell, one-by-one
# 2. Use the command "setLayerTransparenciesTo(75)" to change every transparency to 75, or whatever you want
# (As a side note, notice that the Group Layers are set to 0 transparency. Play with this if you want!)
#
# Feel free to use, rewrite, and distribute as you wish.
#
##################################################################################################################
import arcpy
# If you plan on using this code outside of an ArcMap session, swap out "CURRENT" with your MXD path here
mxd = arcpy.mapping.MapDocument("CURRENT")
# The UpdateLayer function lower down requires you provide it an explicit Data Frame. Change this if you need to
df = arcpy.mapping.ListDataFrames( mxd , "Layers" )[0]
# Create a list of all the Layers in your MXD's Data Frame of choice
allLayers = arcpy.mapping.ListLayers( mxd, "*", df )
# This is the function that takes your Transparency input and actually applies it to all the layers you told it to
def setLayerTransparenciesTo ( tpv ):
for layer in allLayers:
if layer.isGroupLayer:
layer.transparency = 0
layer.visible = True
else:
layer.transparency = tpv
layer.visible = True
arcpy.mapping.UpdateLayer( df, layer, layer, False )
# This is just an extra function I included so you can confirm that all the layers got changed how you want them to
# You could fancy this simple report to your liking using additional Layer object properties
def layerReport ():
for layer in allLayers:
print layer.isGroupLayer, layer.transparency, layer.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment