I created a script tool that positions the north arrow, legend, scale bar, and title in a layout; and then zooms to a bookmark and exports the layout as a PDF. But when I go and look at the PDF, the legend does not display the graduated color symbology from the results of a summarize with-in, but will display one of my point layers. However, when I go and look at the layout in ArcGIS Pro the graduated color symbology is displayed in the layout legend.

Here is the custom script tool I'm using:

import arcpy

#input layer
lyr = arcpy.GetParameterAsText(0)

# input name of layout
p = arcpy.mp.ArcGISProject("CURRENT")
lyt = p.listLayouts("Layout_King")[0]

# Reposition the scale bar
scaleBar = lyt.listElements("MAPSURROUND_ELEMENT", "Scale Bar")[0]
mf = scaleBar.mapFrame
scaleBar.elementPositionX = mf.elementPositionX + 0.0
scaleBar.elementPositionY = mf.elementPositionY - 0.5

# Reposition the north arrow
northArrow = lyt.listElements("MAPSURROUND_ELEMENT", "North Arrow")[0]
mf = northArrow.mapFrame
northArrow.elementPositionX = mf.elementPositionX + 8.8
northArrow.elementPositionY = mf.elementPositionY + 0.7

# Align the title with the center of the map frame
title = lyt.listElements("TEXT_ELEMENT", "Name of Map Text")[0]
mf = lyt.listElements('MAPFRAME_ELEMENT',"Map Frame")[0]
title.elementPositionX = mf.elementPositionX + (mf.elementWidth / 3.7)
title.elementPositionY = mf.elementPositionY + (mf.elementHeight / 0.98)

# Reposition the Legend and fix legend title
legend = lyt.listElements("LEGEND_ELEMENT", "Legend")[0]
legend.title = "Legend"
legend.elementPositionX = mf.elementPositionX + 4.8
legend.elementPositionY = mf.elementPositionY + 6.15

# setting layout to bookmark
aprx = arcpy.mp.ArcGISProject("Current")

# add name of layout
lyt = aprx.listLayouts("Layout_King")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT")[0]

# add name of bookmark
bkmks = mf.map.listBookmarks()
bkmks.sort(key=lambda x: x.name, reverse=True)
for bkmk in bkmks:
      lyt.exportToPDF(r"C:\arcGIS_Shared\Exports" + "\\" + bkmk.name + ".pdf")

Is there something I'm doing wrong, or missing?

Also I'm using this custom script tool ModelBuilder

I tried using legend.updateItem() and legend.updateItem("*"), but it gives me the following error:

AttributeError: 'LegendElement' object has no attribute 'updateItem'

closed as off-topic by PolyGeo May 29 '18 at 23:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Perhaps you need to updateItem on the legend element resources.arcgis.com/en/help/main/10.2/index.html#/… to force it to refresh between zoomToBookmark and exportToPDF. – Michael Stimson Nov 28 '17 at 23:50
  • I tried that, but it gives me the following error. AttributeError: 'LegendElement' object has no attribute 'updateItem' – Matt A. Nov 29 '17 at 19:29
  • 2
    OP is using ArcGIS Pro, I dont see updateItem on LegendElement pro.arcgis.com/en/pro-app/arcpy/mapping/legendelement-class.htm That will be an arcpy.mapping (ArcMap) property only. – KHibma Nov 29 '17 at 20:07
  • 2
    Simply as a guess (I'd have to test to know for sure), this could be an exporting issue. The help for LegendElement mentions how it works dynamically with the map contents. arcpy.mp does not have the same refresh commands that arcpy.mapping did. Everything is supposed to be responsive. It might be a bug, it might not be designed to work with exporting, it might be some trivial to make it work. – KHibma Nov 29 '17 at 20:11
  • Please present a code snippet rather than your whole code. For example, the north arrow looks like it would be unrelated to the issue that you describe so your code could be simplified by removing that. – PolyGeo May 29 '18 at 23:45