OSError in exportToPNG()

383
1
09-26-2024 01:19 AM
-_-
by
Frequent Contributor

A script I've been using until now is no longer working.
It's a script that outputs the active layout to a png file.
The cause seems to be exportToPNG(), so I tried extracting just that part, but I get the same error.
Below is the relevant code.

import arcpy
import os

arcpy.env.overwriteOutput=True
aprx=arcpy.mp.ArcGISProject("CURRENT")
activeLayout=aprx.activeView
activeLayout.exportToPNG(r"D:\test.png",resolution=300)

 

I get the following error:

 

Traceback (most recent call last):
  File "D:\Python\PRO\test.py", line 12, in <module>
    activeLayout.exportToPNG(r"D:\test.png",resolution=300)
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\utils.py", line 186, in fn_
    return fn(*args, **kw)
           ^^^^^^^^^^^^^^^
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 3480, in exportToPNG

Traceback (most recent call last):
  File "D:\Python\PRO\test.py", line 12, in <module>
    activeLayout.exportToPNG(r"D:\test.png",resolution=300)
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\utils.py", line 186, in fn_
    return fn(*args, **kw)
           ^^^^^^^^^^^^^^^
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 3480, in exportToPNG
    return convertArcObjectToPythonObject(self._arc_object.exportToPNG(*gp_fixargs((out_png, resolution, False, color_mode, transparent_background, embed_color_profile, clip_to_elements), True)))
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: D:\test.png

 

When I look at the output folder, "test.png" is output for a moment and then disappears, and after it disappears I get an error.
What's strange is that, depending on the layout, I can output without any errors using this code.

I'm really stuck. Are there any possible reasons for this?

0 Kudos
1 Reply
-_-
by
Frequent Contributor

Additional note.

I found that this error occurs only when a specific color profile is used in the layout color management, and png output is not possible. I contacted support and they confirmed the same phenomenon.

It may not be a python problem.