Skip to content

Instantly share code, notes, and snippets.

@alexfriant
Last active July 4, 2023 23:03
Show Gist options
  • Save alexfriant/0f4056f75ca7dd06eaa3195ea0dc0c97 to your computer and use it in GitHub Desktop.
Save alexfriant/0f4056f75ca7dd06eaa3195ea0dc0c97 to your computer and use it in GitHub Desktop.
set the minimum scale values for all layers in an mxd that don't have minimum scale values already set (the don't show out-beyond scale)
#################################################################################
#
# Requirements: You'll need ArcGIS Desktop 10.1 or higher with Python 2.7
#
# If you are publishing an MXD as a map service you might get a warning from
# the Analyze option that some number of layers "draws at all scale ranges".
#
# This script sets all the layers in the MXD you have open to a minimum scale
# value of your choosing IF a layer's value is not set (indicated by being 0.0).
#
# It shows a list before the values were changed, and it lists them again after
# they were set. The lists are in layer_name: scale pairs.
#
# i.e.: Fire Hydrants: 10000.0
#
# Instructions: This is code you can copy/paste into the ArcMap Python
# interactive console with the MXD open that you wish to review.
#
# You can paste it all, or you can paste a little bit at a time to modify what
# ever needs changing to your needs.
#
# Feel free to use, rewrite, and distribute as you wish.
# As always, use at your own risk!
#
#################################################################################
# set your mxd and get list of layers
mxd = arcpy.mapping.MapDocument("CURRENT")
lyrs = arcpy.mapping.ListLayers(mxd)
# output a list of layer: scale pairs to the console
print "BEFORE update: "
for lyr in lyrs:
print lyr.name + ": " + str(lyr.minScale)
# set your minimum scale level (won't show out beyond)
min = 9244648.86862
# set them if 0
print "\nAFTER update: "
for lyr in lyrs:
if lyr.minScale == 0: # remove this conditional if you want to change ALL layers
lyr.minScale = min
print lyr.name + ": " + str(lyr.minScale)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment