How to create offline_areas using extent

376
0
04-03-2020 02:27 AM
AgrimotionTeam
New Contributor II
Hi,
I am trying to set layers in a webmap to be available for offline use without success.  I want to create the offline areas using the layer extent, since I cannot create bookmarks from within python.  I would greatly appreciate any assistance.  
I've written the following Python routine (using arcgis 1.7.0):
def enable_offline_use(gis, wm): 
    #get each layer's extent and title
    for layer in wm.layers:
        layer_obj = gis.content.get(layer['itemId'])
        item_prop = {'title': layer_obj.title }

        #make available offline
        wm.offline_areas.create(layer_obj.extent, item_prop)
    wm.offline_areas.update()
This fails at the create call with:
... line 116, in enable_offline_use  
  wm.offline_areas.create(layer_obj.extent, item_prop)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\mapping\_types.py", line 1296, in create
    elif isinstance(area, Envelope) or \
NameError: name 'Envelope' is not defined
_types.py does not import Envelope.  I can update the file as follows:
from arcgis.geometry import SpatialReference, Polygon, Envelope
Now it goes past this point, but when turning on verbose I get the following error:
INFO:arcgis.geoprocessing._tool:Running script CreateMapArea...
object of type 'NoneType' has no len()
ERROR:arcgis.geoprocessing._tool:object of type 'NoneType' has no len()
Completed script CreateMapArea...
INFO:arcgis.geoprocessing._tool:Completed script CreateMapArea...
Failed to execute (CreateMapArea).
ERROR:arcgis.geoprocessing._tool:Failed to execute (CreateMapArea).
So to summarize:
  1. Should I be adding "Envelope" to the _types.py file, or is my configuration missing something?
  2. Am I doing something obviously wrong in my script?

Thanks.

0 Kudos
0 Replies