Using MVVM's to open project with existing Map Pane View?

1022
11
Jump to solution
04-05-2023 07:26 AM
KT81
by
New Contributor III

I'm using Visual Studio with ArcGIS Pro SDK my current version of ArcGIS Pro is  3.1.0, A co-worker has created a python scripted that took 77 mxd's and converted them to aprx files, each one has an existing map in the Catalog pane associated with the map, but when you open the aprx there is no map pane view opened.  I was looking in the configuration of the ArcGIS Pro SDK and it seems like there should be a method to have the MVVM look to see if there is a map associated with the project and open that map in a map pane view.  I have narrowed down the location to be the ViewModel for the sdk configuration is where I should add an ICommand Interface or maybe another piece of code that adds this function to the "browse to project" functionality of the configuration,  but I haven't been able to find the documentation on how that command is called into the model view.  I was hoping someone could give me a little direction on if I am indeed correct or if there is another function / method I should be considering.

 

so this article goes into what I am trying to do but the I am not trying to use an OnClick method but use the View Model in the configuration to always check the project for a Map and open it up on startup of the project.

https://community.esri.com/t5/arcgis-pro-sdk-questions/open-an-existing-map/td-p/791296

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I attached a sample add-in project that opens all .aprx projects under a given folder (including all .aprx file in subfolders) and checks if the aprx has an open Map Pane, if it doesn't have an open Map Pane, the add-in takes the first Map and creates a map pane, then saves the project file.

Note that you might get prompted for input at some time and execution is slow at times because the add-in is using time outs for some operations.

To use the app, set a start folder and click the start button. 

Wolf_0-1680883289771.png

 

View solution in original post

11 Replies
RichardDaniels
Occasional Contributor III
Since you converted the MXDs to aprx why are you surprised that the default map is not 'open'? Go to the Catalog View pane, map folder, and open the map from there.
To do it programmatically you would need to grab the map document collection then, since you know there is only one map, you could do something like map[[0].open(). Otherwise you would need to search the collection by Name.
0 Kudos
KT81
by
New Contributor III

Also do you have any examples of this in use or documentation links?

0 Kudos
KT81
by
New Contributor III

Well the main reason I need to do this programmatically is because their are 77 of these mxd's that were converted to aprx's and this way I or someone else wouldn't need to open 77 aprxs' all over again.

0 Kudos
KT81
by
New Contributor III

@RichardDaniels thank you for your suggestion about using the map document collection though.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I attached a sample add-in project that opens all .aprx projects under a given folder (including all .aprx file in subfolders) and checks if the aprx has an open Map Pane, if it doesn't have an open Map Pane, the add-in takes the first Map and creates a map pane, then saves the project file.

Note that you might get prompted for input at some time and execution is slow at times because the add-in is using time outs for some operations.

To use the app, set a start folder and click the start button. 

Wolf_0-1680883289771.png

 

KT81
by
New Contributor III

Thanks a lot Wolf and my apologies for taking so long to test this addin, it works very nicely.   I will study this and see if I can follow your workflow process through creating this because I really want to learn how to be a better .net programmer.

0 Kudos
KT81
by
New Contributor III

After testing the tool for a little while I noticed that it will open the first aprx file and open the map pane view but the next one it says it already has a map pane view open even though it doen't have one open, Also once I stop debugging and restart debugging to run the addin again in Pro it will go to the next aprx and open the Map Pane, but I have to run it multiple times.  I have been looking in the "Helpers for Project processing" region my, for some reason it sees the rest of the aprx files as having an opened map pane view even though they don't.  is it possible that when it checks the first aprx that it is still holding on to that map pane as open in the next Aprx file?  I  noticed it is checking for a list of map panes using IEnumerable<IMapPane> Method, I figured I could add an ifelse statement or would changing the syntax where it checks for open mapViews be better?

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Can you send the log output showing the events ? 

0 Kudos
KT81
by
New Contributor III

I have attached the output file from the debug session, I was also able to direct the tool to a specific aprx file just to test it because I was curious if it was the .FirstOrDefault(); method that could be confusing the tool as shown in the snippet image.  I added the below to the code and it worked as I thought it would where it ignored the other 2 aprx files but saw the one called out.

.FirstOrDefault(item => item.Name.Equals("Alfalfa_SD_2020"));

KelbyThomasson_0-1682624925454.png

 

0 Kudos