Open map after importing .mapx using arcpy

2154
7
03-21-2021 09:42 PM
ToyotaT18
New Contributor III

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?

0 Kudos
7 Replies
DanPatterson
MVP Esteemed Contributor

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


... sort of retired...
0 Kudos
MatthewDriscoll
MVP Alum

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)

 

ToyotaT18
New Contributor III

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?

0 Kudos
MatthewDriscoll
MVP Alum

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.  

0 Kudos
DanPatterson
MVP Esteemed Contributor

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.


... sort of retired...
0 Kudos
ToyotaT18
New Contributor III

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.

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

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.


... sort of retired...
0 Kudos