AnsweredAssumed Answered

Getting and Setting map scale and scale bar

Question asked by wwmiller68 Champion on Aug 10, 2015
Latest reply on Aug 13, 2015 by wwmiller68

I put this code together to get and set the map to a known scale. I was wanting to know has anyone else done something like this? Below is the code.

 

def returnScale(dfscale):
    scalebar = [2,3,4,5,6,10]
    dfscale = dfscale/12
    dfscale = str(int(dfscale))
    dfscaleLen = len(dfscale)
    numcheck = int(dfscale[0])
    for each in scalebar:
        if numcheck < each:
            multi = '1'
            while dfscaleLen > 1:
                multi = multi + '0'
                dfscaleLen = dfscaleLen - 1
            scalebar = each * int(multi)
            dataframescale = scalebar * 12
            return scalebar,dataframescale
            break
mxd = arcpy.mapping.MapDocument("CURRENT") 
df = arcpy.mapping.ListDataFrames(mxd)[0]
df.scale = returnScale(df.scale)[1]
arcpy.RefreshActiveView()

Outcomes