Skip to content

Commit f1c005c

Browse files
Fixed project load scenarios on Pro 2.x
1 parent b1d9a5c commit f1c005c

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

arcpyext/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "0.7.26"
1+
__version__ = "0.7.27"
22
__author__ = "David Whittingham; David Payne; Adam Kerz; Peter Reyne; Daniel Baternik; Chris Blanchfield; Gary Bagnall"
33
__copyright__ = "Copyright (C) 2013-2023 David Whittingham"

arcpyext/mapping/_cim/pro_project.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,37 @@ def maps(self):
6060

6161
@property
6262
def _cimgisproject(self):
63-
if not "GISProject" in self._cims:
64-
# check what format support we have on ArcGIS Pro
65-
supports_json_proj = hasattr(CIMGISProject, "FromJson")
66-
supports_xml_proj = hasattr(CIMGISProject, "FromXml")
63+
if "GISProject" in self._cims:
64+
return self._cims["GISProject"]
6765

68-
# read project based on supported file type
66+
# check what format support we have on ArcGIS Pro
67+
supports_json_proj = hasattr(CIMGISProject, "FromJson")
68+
supports_xml_proj = hasattr(CIMGISProject, "FromXml")
69+
70+
# attempt to read project based on supported file type
71+
gis_project = None
72+
73+
if supports_json_proj:
74+
try:
75+
gis_project = CIMGISProject.FromJson(read_file_in_zip(self._proj_zip, "GISProject.json"))
76+
except KeyError:
77+
# JSON file not in project, probably an XML file
78+
pass
79+
80+
if not gis_project and supports_xml_proj:
6981
try:
70-
if supports_json_proj:
71-
self._cims["GISProject"] = CIMGISProject.FromJson(
72-
read_file_in_zip(self._proj_zip, "GISProject.json")
73-
)
74-
elif supports_xml_proj:
75-
self._cims["GISProject"] = CIMGISProject.FromXml(read_file_in_zip(self._proj_zip, "GISProject.xml"))
76-
else:
77-
raise NotImplementedError(
78-
"This version of ArcGIS Pro is unknown and supports neither XML-based or JSON-based CIM Project loading."
79-
)
80-
except KeyError as ke:
81-
raise_from(
82-
NotImplementedError(
83-
"This version of ArcGIS Pro does not support the type of Project you are attempting to open."
84-
), ke
85-
)
82+
gis_project = CIMGISProject.FromXml(read_file_in_zip(self._proj_zip, "GISProject.xml"))
83+
except KeyError:
84+
# XML file not in project, probably a JSON file but maybe we don't have support for that on
85+
# current ArcGIS Pro install
86+
pass
87+
88+
if not gis_project:
89+
raise NotImplementedError(
90+
"This ArcGIS Pro project is either an unknown format or incompatible with the currently installed version of ArcGIS Pro."
91+
)
92+
93+
self._cims["GISProject"] = gis_project
8694

8795
return self._cims["GISProject"]
8896

@@ -91,6 +99,7 @@ def _cimgisproject(self):
9199
#region PUBLIC FUNCTIONS
92100

93101
def close(self):
102+
"""Closes the ArcGIS Project, not required when used inside a 'with' statement."""
94103
if self._proj_zip:
95104
self._proj_zip.close()
96105
self._proj_zip = None

0 commit comments

Comments
 (0)