Select to view content in your preferred language

Change scale bar properties with Python

09-22-2010 07:53 AM
Status: Already Offered
Labels (1)
Occasional Contributor

I want to be able to access and alter scale bar properties such as division values, division numbers, and units via Python.  An ESRI staff member on the ArcObjects forum says it can't be done... yet.

This would help me a lot. I currently have multiple scale bars in one Data Driven Pages MXD that are positioned according to the current scale. It would be nice to just have one that changed the division values and numbers dynamically.
Yep. Been waiting for this for years now.
I did a custom PrintSOE which has this feature:

ay be this can help you until Esri has implemented this feature
I need this to be possible, make map automation much cleaner and make for much better and appropriate cartography.

+100 The ability to dynamically set the properties of a scale bar is paramount in managing advanced webprinting and geoprocessing. Currently we have to setup (and manage!) multiple mxds at slightly different scale settings to ensure that the scale bars and grids/graticules* are actually useful.

*the ability to set the grid/graticule division through arcpy.mapping is also sorely needed.


Just curious what the hold up is for ESRI to implement this?  Seems like a request that has been around for awhile now.


I spoke to a couple of folks on the ESRI arcpy.mapping team about this at UC a couple of years ago. The party line seemed to be that ESRI didn't want to reinvent everything for python that was already available in ArcObjects. I keep hoping if we bug them enough it might happen though. I have to maintain a handful of templates with about 20 named scale bars each to get around this problem, which is kind of ridiculous if you ask me.

Status changed to: Already Offered

Hello everyone and thank you for your feedback! I missed this thread because it wasn't labelled  We exposed Python CIM Access to be able to accommodate these finer grained requests.  Please review this topic:

You should be able to accomplish now using and CIM access. Also in the pipeline on the Layout team (post 3.1) that you might find useful is we plan on adding scale thresholds to layout map surrounds elements so, for example, you can have multiple, stacked scalebars with different settings, scale will control visibility and if you sent the thresholds up correctly, just one scale bar would display at a time.

As for arcpy, here is a script from a downloadable sample that has 30 CIM snippets.  I modified it slightly to also update divisions and subdivisions I saw mentioned in the thread.  Here is a before and after scale bar.




Code sample:

p ='current')
lyt = p.listLayouts('GreatLakes')[0]

lyt_cim = lyt.getDefinition("V2") #Get the layout's CIM definition

#Iterate though all layout elements to find the ScaleBar element
for elm in lyt_cim.elements:
    if == "Scale Bar":
        #Change the number of divisions and subdivision
        elm.divisions = 3
        elm.subdivisions = 2
        #Flip the scale bar so markers and labels appear below the line
        elm.labelPosition = "Below"
        elm.markPosition = "Below"
        #Remove the first midpoint division label by labeling only divisions
        elm.labelFrequency = "Divisions"

lyt.setDefinition(lyt_cim) #Set the layout's CIM definition

The CIM samples can be located here:

Then scroll to the one called CIM Samples