cgarlock

Adding a scale and changing its position

Discussion created by cgarlock on Mar 25, 2013
Latest reply on Nov 10, 2016 by LukeW
I'm having trouble getting this script to run. I get errors saying line 4-list index out of range, and when I comment out the [0] I get an error saying 'list' object has no attribute 'parentDataFrameName' 

I'm trying to actually add the scale bar and add in titles, author etc... with python but I was first trying to get an already inserted scale bar to change its position.

Please help


>>>
#The following script will find the mapsurround element named ScaleBar and change it's position.
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Courtney\TEST.mxd")
scaleBar = arcpy.mapping.ListLayoutElements(mxd, "MAPSURROUND_ELEMENT", "ScaleBar") [0]
df = arcpy.mapping.ListDataFrames(mxd, scaleBar.parentDataFrameName)[0]
scaleBar.elementPositionX = df.elementPositionX + (df.elementWidth / 2)
mxd.save()
del mxd

Outcomes