<?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 Re: python script tool (3 questions) in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608526#M95229</link>
    <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/572892"&gt;@Seyed-MahdySadraddini&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For number 1, I do something like this here:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;output_feature_class = r'C:\Default.gdb\Filtered_Addresses'
map.addDataFromPath(output_feature_class)&lt;/LI-CODE&gt;&lt;P&gt;This adds the feature layer to the map, but this may require an exclusive lock on the project, it has caused issues in the past with me, but may work for you, otherwise, try your original function with a variable that's set as the &lt;STRONG&gt;Absolute&lt;/STRONG&gt; path where it originates from the C:/ drive or other drive you're using.&lt;/P&gt;&lt;P&gt;I'm a little confused about part 2, normally what happens is the tool and toolbox are zipped, and then it's sent out, unpacked, and the toolbox and tool can then be automatically added.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CodyPatterson_0-1745420619940.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/130810i3B4DFD63FC944385/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CodyPatterson_0-1745420619940.png" alt="CodyPatterson_0-1745420619940.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;They can use "Add Toolbox" and add the toolbox that way, but I could be interpreting this incorrectly, please correct me if so!&lt;/P&gt;&lt;P&gt;For part 3, here is how to upload a custom python package, which should include your tool:&lt;/P&gt;&lt;P&gt;&lt;A href="https://enterprise.arcgis.com/en/server/latest/publish-services/windows/deploying-custom-python-packages.htm" target="_blank"&gt;https://enterprise.arcgis.com/en/server/latest/publish-services/windows/deploying-custom-python-packages.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
    <pubDate>Wed, 23 Apr 2025 15:05:38 GMT</pubDate>
    <dc:creator>CodyPatterson</dc:creator>
    <dc:date>2025-04-23T15:05:38Z</dc:date>
    <item>
      <title>python script tool (3 questions)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608429#M95216</link>
      <description>&lt;P&gt;I have made my python script tool. I have several questions I am hoping to get answers for:&lt;/P&gt;&lt;P&gt;(Note:&amp;nbsp;I am using ArcGIS Pro 3.1)&lt;/P&gt;&lt;P&gt;1. The tool generates the desired layer in the current geodatabase. It has to be added to the content pane manually for display. However, I want the layer to be added to the display automatically upon generation. I have added the below code to the tool but there is error when it gets to the last line:&lt;/P&gt;&lt;P&gt;# ArcGIS map interface&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;m = aprx.listMaps()[0]&lt;BR /&gt;m.addLayer(layer_name)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR:&lt;/P&gt;&lt;P&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\utils.py", line 191, in fn_&lt;BR /&gt;return fn(*args, **kw)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 2560, in addLayer&lt;BR /&gt;return convertArcObjectToPythonObject(self._arc_object.addLayer(*gp_fixargs((add_layer_or_layerfile, add_position), True)))&lt;BR /&gt;ValueError: test1_April23&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;test1_April23&lt;/STRONG&gt;&amp;nbsp;layer generated and it exists in the current geodatabase! I don't understand why m.addLayer(layer_name) is causing an error! How else should I accomplish this task of automatically adding the generated layer to contents for display?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SeyedMahdySadraddini_0-1745411552318.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/130791iBB79E11D82967A4F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SeyedMahdySadraddini_0-1745411552318.png" alt="SeyedMahdySadraddini_0-1745411552318.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. When I share the python script tool with other people, I understand I can just zip the toolbox and the script file together and send it away. The issue is that the toolbox will look for the script at a designated directory. If that directory does not exist, the tool will have no associated code; unless the operator copies and pastes the code from the script file I sent them. Is there a way to avoid this requirement, so the operator does not have to manually open the script file to copy/paste the code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Could the python script tool be shared with everybody through ArcGIS Enterprise?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 12:33:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608429#M95216</guid>
      <dc:creator>Seyed-MahdySadraddini</dc:creator>
      <dc:date>2025-04-23T12:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: python script tool (3 questions)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608468#M95218</link>
      <description>&lt;P&gt;For #1 I think you need to use the explicit path to Pro project in a tool and not current.&amp;nbsp; I believe there are other past forum posts that have discussed this issue.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 14:00:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608468#M95218</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2025-04-23T14:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: python script tool (3 questions)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608526#M95229</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/572892"&gt;@Seyed-MahdySadraddini&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For number 1, I do something like this here:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;output_feature_class = r'C:\Default.gdb\Filtered_Addresses'
map.addDataFromPath(output_feature_class)&lt;/LI-CODE&gt;&lt;P&gt;This adds the feature layer to the map, but this may require an exclusive lock on the project, it has caused issues in the past with me, but may work for you, otherwise, try your original function with a variable that's set as the &lt;STRONG&gt;Absolute&lt;/STRONG&gt; path where it originates from the C:/ drive or other drive you're using.&lt;/P&gt;&lt;P&gt;I'm a little confused about part 2, normally what happens is the tool and toolbox are zipped, and then it's sent out, unpacked, and the toolbox and tool can then be automatically added.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CodyPatterson_0-1745420619940.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/130810i3B4DFD63FC944385/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CodyPatterson_0-1745420619940.png" alt="CodyPatterson_0-1745420619940.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;They can use "Add Toolbox" and add the toolbox that way, but I could be interpreting this incorrectly, please correct me if so!&lt;/P&gt;&lt;P&gt;For part 3, here is how to upload a custom python package, which should include your tool:&lt;/P&gt;&lt;P&gt;&lt;A href="https://enterprise.arcgis.com/en/server/latest/publish-services/windows/deploying-custom-python-packages.htm" target="_blank"&gt;https://enterprise.arcgis.com/en/server/latest/publish-services/windows/deploying-custom-python-packages.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 15:05:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608526#M95229</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2025-04-23T15:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: python script tool (3 questions)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608626#M95242</link>
      <description>&lt;P&gt;I used the explicit path to the .aprx file. I am still getting the same ValueError as before. This tells me "CURRENT" can be substituted for the .aprx file as well; please correct me if that is not right!&lt;/P&gt;&lt;P&gt;As for the project path, I tested that as well (project folder path, not the .aprx file); this resulted in OSError.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 17:59:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608626#M95242</guid>
      <dc:creator>Seyed-MahdySadraddini</dc:creator>
      <dc:date>2025-04-23T17:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: python script tool (3 questions)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608660#M95244</link>
      <description>&lt;P&gt;See Below for the fix&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 13:26:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608660#M95244</guid>
      <dc:creator>Seyed-MahdySadraddini</dc:creator>
      <dc:date>2025-04-24T13:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: python script tool (3 questions)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608885#M95258</link>
      <description>&lt;P&gt;fixed it.&lt;/P&gt;&lt;P&gt;# Export data to new Feature Class&lt;BR /&gt;s2 = arcpy.conversion.ExportFeatures(s, layer_name)&lt;BR /&gt;arcpy.AddMessage(f'The name of the layer created in the default geodatabase is: {layer_name}')&lt;/P&gt;&lt;P&gt;# ArcGIS map interface&lt;BR /&gt;display_layer = arcpy.Describe(s2).catalogPath&lt;BR /&gt;arcpy.AddMessage(f'Path to the display layer is: {display_layer}')&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;m = aprx.listMaps()[0]&lt;BR /&gt;m.addDataFromPath(display_layer)&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/712076"&gt;@CodyPatterson&lt;/a&gt;&amp;nbsp;for your guidance!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 13:25:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608885#M95258</guid>
      <dc:creator>Seyed-MahdySadraddini</dc:creator>
      <dc:date>2025-04-24T13:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: python script tool (3 questions)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608898#M95259</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/572892"&gt;@Seyed-MahdySadraddini&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great job! Glad you got that checked out, hopefully that solves most of your problems!&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 13:52:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-tool-3-questions/m-p/1608898#M95259</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2025-04-24T13:52:32Z</dc:date>
    </item>
  </channel>
</rss>

