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.