Skip to content

Commit

Permalink
Fixed project load scenarios on Pro 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidWhittingham committed Aug 2, 2023
1 parent b1d9a5c commit f1c005c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion arcpyext/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.7.26"
__version__ = "0.7.27"
__author__ = "David Whittingham; David Payne; Adam Kerz; Peter Reyne; Daniel Baternik; Chris Blanchfield; Gary Bagnall"
__copyright__ = "Copyright (C) 2013-2023 David Whittingham"
51 changes: 30 additions & 21 deletions arcpyext/mapping/_cim/pro_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,37 @@ def maps(self):

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

# read project based on supported file type
# check what format support we have on ArcGIS Pro
supports_json_proj = hasattr(CIMGISProject, "FromJson")
supports_xml_proj = hasattr(CIMGISProject, "FromXml")

# attempt to read project based on supported file type
gis_project = None

if supports_json_proj:
try:
gis_project = CIMGISProject.FromJson(read_file_in_zip(self._proj_zip, "GISProject.json"))
except KeyError:
# JSON file not in project, probably an XML file
pass

if not gis_project and supports_xml_proj:
try:
if supports_json_proj:
self._cims["GISProject"] = CIMGISProject.FromJson(
read_file_in_zip(self._proj_zip, "GISProject.json")
)
elif supports_xml_proj:
self._cims["GISProject"] = CIMGISProject.FromXml(read_file_in_zip(self._proj_zip, "GISProject.xml"))
else:
raise NotImplementedError(
"This version of ArcGIS Pro is unknown and supports neither XML-based or JSON-based CIM Project loading."
)
except KeyError as ke:
raise_from(
NotImplementedError(
"This version of ArcGIS Pro does not support the type of Project you are attempting to open."
), ke
)
gis_project = CIMGISProject.FromXml(read_file_in_zip(self._proj_zip, "GISProject.xml"))
except KeyError:
# XML file not in project, probably a JSON file but maybe we don't have support for that on
# current ArcGIS Pro install
pass

if not gis_project:
raise NotImplementedError(
"This ArcGIS Pro project is either an unknown format or incompatible with the currently installed version of ArcGIS Pro."
)

self._cims["GISProject"] = gis_project

return self._cims["GISProject"]

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

def close(self):
"""Closes the ArcGIS Project, not required when used inside a 'with' statement."""
if self._proj_zip:
self._proj_zip.close()
self._proj_zip = None
Expand Down

0 comments on commit f1c005c

Please sign in to comment.