Hello everyone,
I have a process I am developing which uses one project ("Project A.aprx") to create then optionally open another project ("Project B.aprx").
The user opens Project A, selects a parcel then runs a script. The script will create a new folder on the network for Project B, then it will extract a project template file (.aptx) into the folder. It will continue on doing a number of other processes and then at the end it will either open Project B (or not) based on whether or not the user selected the checkbox on the initial script form to open the project.
Irregardless of whether or not the 'Open Project' is checked (i.e. the script opens Project B or the user opens Project B) when Project B opens it opens as Read Only.
This is the case as long as Project A is still open. If the user closes Project A and then opens Project B it will open in write mode (which is what I want).
Possible Solutions:
1. Can the script close Project A after initiating opening Project B? I'm not sure if this is possible with arcpy (I'm betting not). But I'd rather not do this as the user may want to keep Project A open and create a Project C, D, E... after creating Project B.
2. Figure out what's happening on the Project A side of things that it's locking Project B and preventing it from opening in write mode. This is what I'd really like to figure out.
I'm using ArcGIS Pro 2.6.3 but have tested this in 2.4.3 and 2.7 and there's no difference.
Any ideas/insights much appreciated.
Thanks All!
Are the projects accessing file or enterprise geodatabases?
There is nothing in arcpy, but you might check the arcgis module.
It makes sense to me to close the first before opening the second. Just warn them to create C, D etc before closing A... unless it is a "need" versus a "nice"
Thanks Dan. Ya, both file and enterprise. I'm currently stepping through the program trying to narrow down which procedure is creating the lock. More to come...
It may turn out that the simplest solution may be to as you said Dan, have the user create all of their projects from Project A, have the script open none of them (even remove that parameter from the form). Then when done creating projects, close Project A and then the user can open the others to work on and there should be no issue.
So after much testing I have narrowed the issue down to the following procedure:
def ExportImage(prj, mapName, lyrExtent, lytName, mapScale, pngFilePath):
if prj == 'current':
aprx = arcpy.mp.ArcGISProject('current')
else:
aprx = arcpy.mp.ArcGISProject(prj)
m = aprx.listMaps(mapName)[0]
lyr = m.listLayers(lyrExtent)[0]
lyt = aprx.listLayouts(lytName)[0]
mf = lyt.listElements("mapframe_element", "Map Frame")[0]
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))
mf.camera.scale = mapScale
lyt.exportToPNG(pngFilePath, resolution=300, color_mode = '8-BIT_ADAPTIVE_PALETTE')
del aprx
and specifically these lines:
m = aprx.listMaps(mapName)[0]
lyr = m.listLayers(lyrExtent)[0]
I'm at a bit of a loss as to why this is happening. I do use these lines of code in other procedures without issue.
Trying:
del lyr
del m
makes no difference.
I suppose I could remove this whole 'Create Images' part from this program and have the user run 'Create Image' once Project B has opened (in write mode). But it would be really nice to figure out what the issue here is.
To provide a final update. I've decided to set enabled = False for the 'Open Project' parameter. If in the future, a solution comes around for this read only issue I can change it back to true.
The users will be instructed to do all their project creation in Project A then to close Project A before opening any of the projects to do any work on them.
Thanks.