Publishing specific layers from ArcGIS Pro map with ArcPy

677
0
11-05-2019 09:44 AM
GregSmith2
New Contributor III

Hello,

I am trying to write a Python script to publish a hosted feature service from selected layers in a map, which is called from my .NET ArcGIS Pro add-in.

If I do not specify any layers from the map to publish (publish all layers), then the service gets published successfully. However, if I do try to specify certain layers to get published, then I receive this error:

   Traceback (most recent call last):
   File "<string>", line 79, in execute
   File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sharing.py", line 23, in exportToSDDraft
   return _convertArcObjectToPythonObject(self._arc_object.exportToSDDraft(out_sddraft, self))
   ValueError: Project does not exist or is inaccessible.
   Failed to execute (PublishHostedFeatureService).

Here is my code, which is failing on the last line:

current_project = arcpy.mp.ArcGISProject("CURRENT")
current_map = current_project.activeMap
layer_list = []

# layer_names is the parameter passed to the tool
for layer_name in layer_names:
    layers = current_map.listLayers(layer_name)
    if len(layers) > 0:
        layer_list.append(layers[0])

sharing_draft = current_map.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", service_name, layer_list)
sharing_draft.exportToSDDraft(sddraft_output_filename)

Am I doing something wrong with how I am passing the layer information to getWebLayerSharingDraft()?

0 Replies