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 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CURRENT"</SPAN><SPAN class="punctuation token">)</SPAN>
current_map <SPAN class="operator token">=</SPAN> current_project<SPAN class="punctuation token">.</SPAN>activeMap
layer_list <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># layer_names is the parameter passed to the tool</SPAN>
<SPAN class="keyword token">for</SPAN> layer_name <SPAN class="keyword token">in</SPAN> layer_names<SPAN class="punctuation token">:</SPAN>
layers <SPAN class="operator token">=</SPAN> current_map<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN>layer_name<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>layers<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN>
layer_list<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>layers<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
sharing_draft <SPAN class="operator token">=</SPAN> current_map<SPAN class="punctuation token">.</SPAN>getWebLayerSharingDraft<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"HOSTING_SERVER"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"FEATURE"</SPAN><SPAN class="punctuation token">,</SPAN> service_name<SPAN class="punctuation token">,</SPAN> layer_list<SPAN class="punctuation token">)</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>exportToSDDraft<SPAN class="punctuation token">(</SPAN>sddraft_output_filename<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Am I doing something wrong with how I am passing the layer information to getWebLayerSharingDraft()?