Select to view content in your preferred language

Downloading Selected Attachments

454
2
10-30-2023 08:36 AM
RobertBorchert
Honored Contributor

I would like to find out how to download selected attachments.

I have used the script below and followed instructions to create a script in Pro and download the attachments to a specific folder. What I would like to do is add an SQL query so I can specify the attachments I want to download.

I set up the script tool to use  SQL query  and specified the name of the column

RobertBorchert_0-1698680129663.png

However the query has no values.

RobertBorchert_1-1698680174083.png

Below is the script I used from the help docs 

 

 

import arcpy
from arcpy import da
import os

inTable = arcpy.GetParameterAsText(0)
fileLocation = arcpy.GetParameterAsText(1)

with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:
for item in cursor:
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

and 

0 Kudos
2 Replies
DavidSolari
Frequent Contributor

SQL Expression parameters require a "Dependency" on the parameter you want to filter so it can populate the dialog, set that up and your parameter should work

0 Kudos
RobertBorchert
Honored Contributor

thanks do you have an example that I could add to the script

0 Kudos