After importing a .mapx map file using importDocument(), it appears in the Catalog. Is there a way to then open that map window using arcpy?
We are 3 years later but I found a solution:
from arcpy.mp import ArcGISProject project = ArcGISProject('current') new_map_path = r"<path_to_mapx_file>" new_map = project.importDocument(new_map_path ) new_map.openView()
works for me in ArcGIS Pro 3.2.2
Yep they eventually added the openView() function for maps and layouts.
Not that I can figure out. When I run into situations like this in Pro I will use Tasks. You can have the python script run but don't include the importDocument in a step, make a new step to Import Map (noting exactly how/where to get the map file), ect. You can have each step run automatically one right after another. Not ideal, but if you need a bit of handholding for those less familiar with the software it works great.
Also, you might be able to do this with the Pro SDK within IProjectItem then AddItem.
That's what I though. In my initial post, I couldn't find any "open" method in either of the links...
I am wondering if you have to construct it from an active mapview, but I definitely haven't tested.
Hi Dan, as stated in my initial post, my intent is to open a map window which has been imported from a .mapx file. I'm trying to get this to work from a custom geoprocessing tool which is run in ArcGIS Pro.
In the GUI if I select Insert -> Import Map and point to the .mapx file, it adds the map to the 'Maps' section of the catalog, and opens the map window too.
In Arcpy if I use aprx.importDocument('.mapx file') it adds the map to the catalog but doesn't open the map window. I'm trying to work out if I can then open the map window using arcpy.
Hopefully that makes the intent more clear, thanks.
it opens a new instance.
What is it you want to do?
You can access properties of the aprx etcetera to add to the current project.
It isn't clear what your intent is.
Hi Matthew, that seems to open the file in a new instance of ArcGIS pro, I need it to open in the current session. Do you know if this is possible?
You could try using the os.
import os myfile = r"C:\Path\TestProject.aprx" os.system("start " + myfile)
* After some testing this works better. You could also probably use the subprocess Popen too?
import os myfile = r"C:\Path\TestProject.aprx" os.startfile(myfile)
ArcGISProject—ArcGIS Pro | Documentation
Map—ArcGIS Pro | Documentation
you can get the contents, but there is no "open" method if you follow the arcpy trail
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.