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
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" }
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
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)
I'm also getting "'Layout' object has no attribute 'exportToPAGX'"Was there any resolution to this?Thanks
Paul
Similarly, I receive this error when attempting to export a layout to a PAGX file.
AttributeError: 'Layout' object has no attribute 'exportToPAGX'
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!
Hey John. Did you ever solve this? I addressed a similar JSON serializable error with the following code:
map.getDefinition doesn't return JSON or an object that can be directly serialized to JSON, hence the error. The function returns a CIMMap object that you will have to serialize by hand (not by hand by hand, but write your own function to do it).
I can't seem to make it work ... This line
map_file.write(json.dumps(map_def))
Give me this error:
TypeError: Object of type 'CIMMap' is not JSON serializable
I have tried a few different ways to output the object but so far no luck ...
John Sawicki did you try this? I'm interested to see if it actually worked or not since I can't test.
ArcPy has never been a complete SDK for ArcGIS Desktop. If saving *.mapx files is important, log an enhancement request with Esri Support and submit an ArcGIS Ideas.
I don't know if this will work and can't test*, but you could try getting the CIM definition (>= ArcGIS 2.4) from the map and then use json.dump / json.dumps to write the .mapx file manually.
* corporate IT moves slooowly and we're still on 2.3
Something like:
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> json aprx_path <SPAN class="operator token">=</SPAN> <SPAN class="string token">"path\\to\\your.aprx"</SPAN> mapx_path <SPAN class="operator token">=</SPAN> <SPAN class="string token">"path\\to\\{}.mapx"</SPAN> aprx <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN>aprx_path<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> map <SPAN class="keyword token">in</SPAN> aprx<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Map: "</SPAN> <SPAN class="operator token">+</SPAN> map<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN> map_def <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN>getDefinition<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># <-- Get the CIM definition</SPAN> <SPAN class="keyword token">with</SPAN> open<SPAN class="punctuation token">(</SPAN>mapx_path<SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>map<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'w'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> map_file<SPAN class="punctuation token">:</SPAN> map_file<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN>json<SPAN class="punctuation token">.</SPAN>dumps<SPAN class="punctuation token">(</SPAN>map_def<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
From the documentation - Python CIM access—ArcPy | ArcGIS Desktop
Python CIM accessThe arcpy.mp module ... does not provide access to all properties, settings, and capabilities available in ArcGIS Pro. One reason is to keep the API streamlined, simple, and manageable. Another reason is that ArcGIS Pro is being developed at such a rapid pace that the APIs can't keep up. It may take a release or more before you have access through the managed APIs. Starting with ArcGIS Pro 2.4, Python developers will have fine-grained access to the Cartographic Information Model (CIM) and can access many more settings, properties, and capabilities that are persisted in a project or document....What is the CIMThe CIM is the Esri Cartographic Information Model. It is a map content specification used to document how information that describes various project components is persisted when saved, read, referenced, or opened. The specification is represented as JSON and is used for maps, scenes, layouts, layers, symbols, and styles in ArcGIS applications and APIs.
The arcpy.mp module ... does not provide access to all properties, settings, and capabilities available in ArcGIS Pro. One reason is to keep the API streamlined, simple, and manageable. Another reason is that ArcGIS Pro is being developed at such a rapid pace that the APIs can't keep up. It may take a release or more before you have access through the managed APIs. Starting with ArcGIS Pro 2.4, Python developers will have fine-grained access to the Cartographic Information Model (CIM) and can access many more settings, properties, and capabilities that are persisted in a project or document.
...
The CIM is the Esri Cartographic Information Model. It is a map content specification used to document how information that describes various project components is persisted when saved, read, referenced, or opened. The specification is represented as JSON and is used for maps, scenes, layouts, layers, symbols, and styles in ArcGIS applications and APIs.
Thanks for figuring out what I meant. I also tried saveACopy on a map but no luck. Seems silly that you can save a map "mapx" externally using from the user interface but there appears to be no way to do so in python.
When you say ArcGIS Pro Documents are you referring to an ArcGIS Pro project file (.aprx) that contains multiple maps?
EDIT:
I'm pretty sure you are talking about .aprx files because I see where you can export the maps as a .mapx file in ArcGIS Pro. However I have not been able to find any way to save a mapx in arcpy. I took a look at the arcpy Mapping Module which was designed to access the information inside of a .aprx file:
Introduction to arcpy.mp—ArcPy | ArcGIS Desktop
I also looked in the Map Class for the Mapping Module:
Map—ArcPy | ArcGIS Desktop
I saw no where in the documentation about saving or exporting as a .mapx. I Also tried to see if saveACopy() would work and it did not. Maybe someone else has more insight?
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.