<?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 works in IDLE but not as a tool in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1088887#M44426</link>
    <description>&lt;P&gt;arcpy.Exists(inTable)&amp;nbsp; confirms the existence?&lt;/P&gt;</description>
    <pubDate>Fri, 13 Aug 2021 14:44:24 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-08-13T14:44:24Z</dc:date>
    <item>
      <title>Python script works in IDLE but not as a tool</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1088847#M44421</link>
      <description>&lt;P&gt;I am attempting to create a simple script detailed&amp;nbsp;&lt;A href="https://support.esri.com/en/technical-article/000023581" target="_blank" rel="noopener"&gt;here&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://support.esri.com/en/Technical-Article/000017450" target="_blank" rel="noopener"&gt;here&lt;/A&gt;&amp;nbsp;with the goal of batch exporting attachments from an attachments table.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from arcpy import da
import os

inTable = arcpy.GetParameterAsText(0)
nameField = arcpy.GetParameterAsText(1)
fileLocation = arcpy.GetParameterAsText(2)

desc = arcpy.Describe(inTable)
attTable = desc.file + "__ATTACH"

joinTable = arcpy.management.AddJoin(inTable, 'globalid', attTable, 'rel_globalid')

with da.SearchCursor(joinTable, [attTable + '.data', desc.file + '.' + nameField, desc.file + '.objectid']) as cursor:
    for item in cursor:
        attachment = item[0]
        filenum = str(item[2]) + "_"
        filename = filenum + str(item[1])
        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
        del item
        del filenum
        del filename
        del attachment
del cursor&lt;/LI-CODE&gt;&lt;P&gt;This is the entire script that I have made, designed to find the attachment table based on the user's input table, create a join and then searchcursor through the cursor.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The script appeared to run successfully without errors, but no files were outputted (simple jpgs).&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to test, I simplified the script down to the basic script ESRI provided in the links I inserted above:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
from arcpy import da
import os

inTable = r"Y:\GIS_Projects\****\****\****\ProdGIS.sde\****__ATTACH"
fileLocation = r"\\dc01\profiles\****\Desktop\test"
arcpy.AddMessage("Test")

with arcpy.da.SearchCursor(inTable, ['data', 'att_name', 'attachmentid']) as cursor:
    arcpy.AddMessage("Test2")
    for item in cursor:
        arcpy.AddMessage("Test3")
        attachment = item[0]
        filenum = "ATT" + str(item[2]) + "_"
        filename = filenum + str(item[1])
        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
        del item
        del filenum
        del filename
        del attachment
del cursor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I added a few arcpy.AddMessage's obviously to see where it is running. It outputs my test 1 and 2 fine, but 3 is never hit. File paths are correct, using ArcGIS Pro 2.8.1, using IDLE 3.7.10, Python 3.7.10.&lt;/P&gt;&lt;P&gt;The biggest issue here is that when I run it as a script via the toolbox, it runs fine with no errors but does not export my attachments. However, when I am editing it via IDLE (right click&amp;gt;edit) in ArcGIS Pro and then run the script from there, it executes perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the disconnect between running it in IDLE and ArcGIS Pro?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 13:20:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1088847#M44421</guid>
      <dc:creator>jhakes</dc:creator>
      <dc:date>2021-08-13T13:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Python script works in IDLE but not as a tool</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1088887#M44426</link>
      <description>&lt;P&gt;arcpy.Exists(inTable)&amp;nbsp; confirms the existence?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 14:44:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1088887#M44426</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-08-13T14:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Python script works in IDLE but not as a tool</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1088948#M44436</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/511761"&gt;@jhakes&lt;/a&gt;I created a similar GP tool.&amp;nbsp; The code is slightly different, but it should export all attachments from an attachments table.&amp;nbsp; It's attached below.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 16:50:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1088948#M44436</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-08-13T16:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python script works in IDLE but not as a tool</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1088986#M44440</link>
      <description>&lt;P&gt;I appreciate you linking your tool. It's very similar to what I've created, but I gave it a shot and unfortunately it is still not functioning properly. Seems like it's an ArcGIS issue, not a code issue.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 17:46:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1088986#M44440</guid>
      <dc:creator>jhakes</dc:creator>
      <dc:date>2021-08-13T17:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python script works in IDLE but not as a tool</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1088990#M44441</link>
      <description>&lt;P&gt;I checked for existence for inTable, attTable and joinTable. All exist, still no output. Running the script directly through IDLE heeds the desired results, but through ArcGIS I get nothing. Possibly a setting I have improperly configured? I have attached screenshots of my properties and parameters for the script.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="parameters.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/20861iBD24BF5BBC047FA9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="parameters.png" alt="parameters.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="general.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/20860i12A1DAE559CA0D00/image-size/medium?v=v2&amp;amp;px=400" role="button" title="general.png" alt="general.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 17:50:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1088990#M44441</guid>
      <dc:creator>jhakes</dc:creator>
      <dc:date>2021-08-13T17:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Python script works in IDLE but not as a tool</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1089065#M44454</link>
      <description>&lt;P&gt;Attached is the sample data I used.&amp;nbsp; Can you test with this and see if you get the same error?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 22:09:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1089065#M44454</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-08-13T22:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python script works in IDLE but not as a tool</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1089152#M44465</link>
      <description>&lt;P&gt;This might be a stupid question, but is idle from the arcgis install, or did you install python 3.6 from another source? Is it worth removing all your python libraries and reinstalling from myesri?&lt;/P&gt;</description>
      <pubDate>Sun, 15 Aug 2021 09:12:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1089152#M44465</guid>
      <dc:creator>David_Brooks</dc:creator>
      <dc:date>2021-08-15T09:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: Python script works in IDLE but not as a tool</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1089188#M44470</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jakes_tbx.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/20899iDAA333E57B52DB0A/image-size/large?v=v2&amp;amp;px=999" role="button" title="jakes_tbx.png" alt="jakes_tbx.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;compare script notes between your script and Jake's&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 00:36:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-script-works-in-idle-but-not-as-a-tool/m-p/1089188#M44470</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-08-16T00:36:55Z</dc:date>
    </item>
  </channel>
</rss>

