Select to view content in your preferred language

Legend is not displaying all active features/layers in ArcGIS Pro using ArcPy?

875
0
11-28-2017 01:07 PM
Business_IntelligenceSoftware
Regular Contributor

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. 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:
      mf.zoomToBookmark(bkmk)
      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

0 Kudos
0 Replies