jpedder

DataDrivenPages and ListLayoutElement

Discussion created by jpedder on Mar 26, 2013
Latest reply on Apr 3, 2013 by Wayne_Whitley
I'm running DDP just fine, the maps print, the dynamic test prints everything is hunky dory. Except.....

When I try to change the text in TEXT ELEMENTS directly from my script. I simply can't get the text elements to take the values I'm assigning them. This works just fine in other mxd's that I'm not using with DDP. Is there a difference or limitation specific to DDP that's preventing the elements from being modified?

My code is below, the two text elements are MapDec and MapName. I'm pulling a local declination stored in a FC to assign to MapDec (only a single record exists) and MapName simply gets a string of text.

Thanks in advance for any help

Jon

def doDDP(aSelection, pageNum, aTask):
    """ Input aSelection, pageNum, aTask, mxd """
    iQuery = '"Assignments.Assignment_Number" = {0}'.format(pageNum)
    ddp = mxd.dataDrivenPages
    indexLayer = ddp.indexLayer
    arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION",iQuery)

    arcpy.AddMessage("Creating Map for Assignment # {0} : {1}\Assignment_Map_{2}.pdf".format(str(pageNum), PDFlocation, str(pageNum)))
    magDec = [row[0] for row in arcpy.da.SearchCursor('Incident_Information', ("Declination"))]

    for elm in arcpy.mapping.ListLayoutElements(mxd):
        if elm.name == "MagDec": elm.text = 'Magnetic Declination: {0}'.format(magDec[0])
        if elm.name == "MapName": elm.text = 'Team_Assignment_Map_{0}.pdf'.format(pageNum)

    ddp.exportToPDF('{0}/Team_Assignment_Map_{1}.pdf'.format(PDFlocation,pageNum), "SELECTED")

Outcomes