0

I'm trying to semi-automate exporting a layout in ArcGIS Pro using exportToPNG. I have it set up as a Toolbox script so a user enters the folder in manually, then runs the script. So there is a 'arcpy.GetParametersAsText' piece of the script that requires running it in ArcGIS Pro, I think.

The two issues are, first the PNG being exported is not match the layout I am trying to export. The second issue is that none of the map elements are included (north arrow, legend, etc...). Only the map frame appears in the PNG file.

Here is the code:

# Import modules
import arcpy
import datetime
from datetime import datetime
from arcpy import env
arcpy.env.overwriteOutput = True
scriptName = 'DDR2_png_Export.py'
now = datetime.now()

# Set Variables
PNG_name = 'DDR_Map_' + now.strftime("%Y_%m_%d")
PNG_location = arcpy.GetParameterAsText(0)
PNG_export = PNG_location + '/' + PNG_name


aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps()[0]
map.defaultView.exportToPNG(PNG_export, 6600, 6600, 550, '', '32-BIT_WITH_ALPHA')

# reference - exportToPNG (out_png, width, height, {resolution}, {world_file}, {color_mode}, {embed_color_profile})
1

2 Answers 2

1

You are close. Instead of exporting the map view of your map object, you need to access the layout of your project. This can be done roughly equal to the map access:

lyt = aprx.listLayouts()[0]
lyt.exportToPNG(PNG_export, 6600, 6600, 550, '', '32-BIT_WITH_ALPHA')

The layout contains all your map elements like legend, north arrow, etc. The Map view, as the name suggests, is just a view of your map, not the layout.

0
0

That was definitely the issue, but the tool parameters were a little different too. So just had to reconfigure that.

lyt = aprx.listLayouts()[0]
lyt.exportToPNG(PNG_export, 550, '32-BIT_WITH_ALPHA')
#reference## lyt.exportToPNG (out_png, {resolution}, {color_mode}, {transparent_background}, {embed_color_profile}, {clip_to_elements})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.