Hey Darren,
thanks for your answer. With your help I could make a arcgis extension add-in. Using the Python Add-In Wizard. And it works as I want (UPDATE: It does not. Working code below). In the index layer there is an attribute field which controls the position of the legend. (1 = lower left, 2= upper left, 3= upper right, 4 = lower right).
The position is hardcoded to fit my layout.
Here the code I use (don't know how to enable the code tag you are using )
<<<<<<<<<
import arcpy
import pythonaddins
class ExtensionClass1(object):
"""Implementation for MovableLegend_addin.extension2 (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = True
def pageIndexExtentChanged(self, new_id):
mxd = arcpy.mapping.MapDocument("CURRENT")
legend = arcpy.mapping.ListLayoutElements(mxd,"LEGEND_ELEMENT")[0]
if mxd.dataDrivenPages.pageRow.LegendPOS == 1:
posX = 2
posY = 3.1
elif mxd.dataDrivenPages.pageRow.LegendPOS == 2:
posX = 2
posY = 24.6 - legend.elementHeight
elif mxd.dataDrivenPages.pageRow.LegendPOS == 3:
posX = 19 - legend.elementWidth
posY = 24.6 - legend.elementHeight
elif mxd.dataDrivenPages.pageRow.LegendPOS == 4:
posX = 19 - legend.elementWidth
posY = 3.1
legend.elementPositionY = posY
legend.elementPositionX = posX
>>>>>>>>>
So thanks for your help.
One last question. The addin produces no error if I open an arcgis project with a Data Driven Page Index Layer without the attribute LegendPOS. In this case it does simply nothing. This is good, but is this normal? Do I have to implement an error behavior for doing it right?