I'm trying to create a button that sets the map scale to 24000. I'm working in ArcMap 10.1 and my Python programming skill is rudimentary.

I followed the Python Add-In instructions and the creation was successful - I have a new toolbar and a new button - but nothing happens when I click the button. Here's the code:

import arcpy
import pythonaddins

class ButtonClass13(object):
    """Implementation for ScaleBtn_addin.Scale24 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        mxd = arcpy.mapping.MapDocument('current')
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        df.scale = 24000

What's missing?


The sharp eyes of a coworker showed me that the scale had changed and was showing as 1:24,000. Refreshing the map then displayed it at the new scale.

Adding arcpy.RefreshActiveView() at the end of the code took care of the problem.

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.