<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Publishing specific layers from ArcGIS Pro map with ArcPy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/publishing-specific-layers-from-arcgis-pro-map/m-p/742632#M57404</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Traceback (most recent call last):&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;File "&amp;lt;string&amp;gt;", line 79, in execute&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sharing.py", line 23, in exportToSDDraft&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;return _convertArcObjectToPythonObject(self._arc_object.exportToSDDraft(out_sddraft, self))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ValueError: Project does not exist or is inaccessible.&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;Failed to execute (PublishHostedFeatureService).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code, which is failing on the last line:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;current_project &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ArcGISProject&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
current_map &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; current_project&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;activeMap
layer_list &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# layer_names is the parameter passed to the tool&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; layer_name &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; layer_names&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    layers &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; current_map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;layer_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;layers&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        layer_list&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;layers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

sharing_draft &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; current_map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getWebLayerSharingDraft&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"HOSTING_SERVER"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"FEATURE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; service_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; layer_list&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
sharing_draft&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;exportToSDDraft&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;sddraft_output_filename&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am I doing something wrong with how I am passing the layer information to getWebLayerSharingDraft()?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 07:36:23 GMT</pubDate>
    <dc:creator>GregSmith2</dc:creator>
    <dc:date>2021-12-12T07:36:23Z</dc:date>
    <item>
      <title>Publishing specific layers from ArcGIS Pro map with ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/publishing-specific-layers-from-arcgis-pro-map/m-p/742632#M57404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Traceback (most recent call last):&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;File "&amp;lt;string&amp;gt;", line 79, in execute&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sharing.py", line 23, in exportToSDDraft&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;return _convertArcObjectToPythonObject(self._arc_object.exportToSDDraft(out_sddraft, self))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ValueError: Project does not exist or is inaccessible.&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;Failed to execute (PublishHostedFeatureService).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code, which is failing on the last line:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;current_project &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ArcGISProject&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
current_map &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; current_project&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;activeMap
layer_list &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# layer_names is the parameter passed to the tool&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; layer_name &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; layer_names&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    layers &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; current_map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;layer_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;layers&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        layer_list&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;layers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

sharing_draft &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; current_map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getWebLayerSharingDraft&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"HOSTING_SERVER"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"FEATURE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; service_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; layer_list&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
sharing_draft&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;exportToSDDraft&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;sddraft_output_filename&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am I doing something wrong with how I am passing the layer information to getWebLayerSharingDraft()?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:36:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/publishing-specific-layers-from-arcgis-pro-map/m-p/742632#M57404</guid>
      <dc:creator>GregSmith2</dc:creator>
      <dc:date>2021-12-12T07:36:23Z</dc:date>
    </item>
  </channel>
</rss>

