I am attempting to create a simple script detailed here and here with the goal of batch exporting attachments from an attachments table.
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 cursorThis 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.
The script appeared to run successfully without errors, but no files were outputted (simple jpgs).
In order to test, I simplified the script down to the basic script ESRI provided in the links I inserted above:
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 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.
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>edit) in ArcGIS Pro and then run the script from there, it executes perfectly.
What is the disconnect between running it in IDLE and ArcGIS Pro?