2

I'm trying to implement a tool to import *.pagx files exported from ArcGIS Pro to a project, modify text elements and export the altered layouts back to the *.pagx files. It is pretty easy to export these files via ArcGIS Pro GUI, but I'm struggling to find a way to export these files via ArcPy.

So far I used the following code to modify layout from the individual *.pagx file:

import arcpy

layout = arcpy.mp.ConvertLayoutFileToLayout(r"C:\temp\templates\8x11 Landscape.pagx")
for element in layout.listElements('TEXT_ELEMENT'):
    if element.name == 'Text 4':
        element.text = "New text"

but there is no way to save the modified layout object as a file. Also I tried to loop through the layouts, imported to the Pro project

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Users\username\Documents\ArcGIS\Projects\Layouts\Layouts.aprx")

for layout in aprx.listLayouts():
    for element in layout.listElements('TEXT_ELEMENT'):
        if element.name == 'Text 4':
            element.text = "New text"
aprx.save()

Using the save() method I can save the project, but again there is no way to export the *.pagx files. I heard somewhere that I could export these *.pagx files via the .Net API only, but I'm still not 100% sure if such export feature is not implemented in arcpy, or I overlooked something.

Update: Tried to employ jsontocim module, located in "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\cim\cimloader\jsontocim.py"

from arcpy.mp import ConvertLayoutFileToLayout 
from arcpy.cim.cimloader.cimtojson import CimJsonEncoder
from json import dumps
layout = ConvertLayoutFileToLayout(r"C:\temp\templates\8x11 Landscape.pagx")
cim = layout.getDefinition('V2')
outJSON = dumps(cim, cls=CimJsonEncoder, indent=2)
print(outJSON)

It produced the output, resembling the structure of the *.pagx file, exported via GUI ,but some parts are missing or their structure differs from the original file.

  • Tried to employ jsontocim module, located in "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\cim\cimloader\jsontocim.py" from arcpy.mp import ConvertLayoutFileToLayout from arcpy.cim.cimloader.cimtojson import CimJsonEncoder from json import dumps layout = ConvertLayoutFileToLayout(r"C:\temp\templates\8x11 Landscape.pagx") cim = layout.getDefinition('V2') outJSON = dumps(cim, cls=CimJsonEncoder, indent=2) print(outJSON) It produced the output, resembling the structure of the *.pagx file, exported via GUI ,but some parts are missing or their structure differs from the original file – Gol Aug 14 '19 at 18:12
  • Please use the edit button beneath your question to revise it with any additional information. – PolyGeo Aug 26 '19 at 22:13
0

As it stands, there is no out of the box function to do this. I actually submitted this as an enhacnement request a few months ago. It's currently "in product plan", meaning that Esri plans on doing it. As of writing (2.4.1), it has not been implemented.

Tracking reference:

ENH-000119472 The ability to export the layout in ArcGIS Pro to a .pagx file through Python

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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