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:
<SPAN class="keyword token">import</SPAN> arcpy
layout <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ConvertLayoutFileToLayout<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"C:\temp\templates\8x11 Landscape.pagx"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> element <SPAN class="keyword token">in</SPAN> layout<SPAN class="punctuation token">.</SPAN>listElements<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'TEXT_ELEMENT'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> element<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">==</SPAN> <SPAN class="string token">'Text 4'</SPAN><SPAN class="punctuation token">:</SPAN>
element<SPAN class="punctuation token">.</SPAN>text <SPAN class="operator token">=</SPAN> <SPAN class="string token">"New text"</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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()<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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.