Save mapx file using python

5255
15
09-20-2019 08:02 AM
JohnSawicki1
New Contributor

I am looking to save some but not all of my  Maps in an ArcGIS Pro document as templates. I know I can save the layers out using python but can't find a way to save the "mapx" file using python. I am saving these pieces tp put them into source control. 

Thanks 

John 

0 Kudos
15 Replies
Yuhash
by
Occasional Contributor

I am using ArcGIS Pro v2.5.1 and am unable to export a 'mapx' file form the console. When calling the method as described under the help documentation for 'Map'  with the line:

aprx = arcpy.mp.ArcGIS Project('CURRENT')

m = aprx.activeMap

m.exportToMAPX('Template.mapx')

I receive the following error:

Traceback (most recent call last):
File "<string>", line 3, in <module>
AttributeError: 'Map' object has no attribute 'exportToMAPX'

Any advice or redirection to resources would be much appreciated!

Tags (3)
0 Kudos
Yuhash
by
Occasional Contributor

Similarly, I receive this error when attempting to export a layout to a PAGX file. 

AttributeError: 'Layout' object has no attribute 'exportToPAGX'

 

0 Kudos
PaulCleverleyArup
New Contributor II

I'm also getting "'Layout' object has no attribute 'exportToPAGX'"

Was there any resolution to this?

Thanks

Paul

0 Kudos
LaurensKusse_hhdelfland
New Contributor II

This worked for me (ArcGIS Pro 2.9.5):

import arcpy
aprx = 'c:\\temp\\project.aprx'
folder = 'c:\\temp\\export'
p = arcpy.mp.ArcGISProject(aprx)
for m in p.listMaps():
    #export mapx file
    mapx_path = f'{folder}\\{m.name}.mapx'
    m.exportToMAPX(mapx_path)

for m in p.listLayouts():
    #export pagx file
    pagx_path = f'{folder}\\{m.name}.pagx'
    m.exportToPAGX(pagx_path)
0 Kudos
MatthewMassey
New Contributor III

This worked for me in the sense that I got a .mapx file, but the data sources for all the layers is not corrrect...they are all basically missing the name of the geodatabase in their source path. For example:

Name of source geodatabase: GEODATABSE.gdb

Correct path to source: PATH\GEODATABASE.gdb

Exported .mapx path to source: PATH\.gdb

0 Kudos
LaurensKusse_hhdelfland
New Contributor II

That's very odd. I think you should contact support about that.

I could not reproduce it. When I open the MapX-file with Visual Studio Code, I see this in the json:

"dataConnection" : {
"type" : "CIMStandardDataConnection",
"workspaceConnectionString" : "DATABASE=X:\\GIS\\Projecten\\3D\\GemaalWestland\\FGDB\\Data.gdb",
"workspaceFactory" : "FileGDB",
"dataset" : "GemaalWestland",
"datasetType" : "esriDTFeatureClass"
}