PROCÉDURE

exporter par lots des pièces jointes d’une classe d’entités

Last Published: May 10, 2024

Résumé

There are no geoprocessing tools that allow users to export and save all attachments locally. The instructions provided below describe how to execute a possible solution by creating a script tool to accomplish the task.

Procédure

To batch export attachments from a feature class, create a script tool from a Python script using the workflow provided below, and run the created script tool.

Note:
This script requires that the input table be the standard attachment table created when attachments are enabled on a feature class. This is because the script relies on the DATA, ATT_NAME and ATTACHMENTID fields stored in this table. The typical naming convention should append _ATTACH to the end of the table name.
  1. Copy and paste the following script into Notepad, and save it as ExportAttachments.py.
    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
    Note:
    This script iterates through the entire attachment table of a single feature class and copies all of the attachments (saved as BLOBs, or binary large objects) to a file.
  2. In the Catalog window, navigate to Toolboxes, and right-click My Toolboxes > New > Toolbox.
An image of adding a new toolbox.
  1. Add a script tool in the new toolbox. Refer to Adding a script tool for steps to do this.
    1. For the Script File, navigate to the location where the ExportAttachments.py script is saved. Select the script, click OK, and click Next.
An image of adding the Script File.
  1. Type Attachments Table in the first row of the Display Name column, and set the Data Type as Table.
  2. Add a second parameter and type Output Location for the Display Name, and set the Data Type as Folder.
An image of configuring the script tool parameters.
  1. Click Finish. A new script tool is added to the toolbox.
  1. Double-click the created script tool to open the tool.
  1. In the dialog box, select the attachments table containing the attachments to be extracted in the Attachments Table parameter.
  2. Under Output Location, select a folder in which to save the exported attachments, and click OK.
An image of the Export Attachments dialog box.
  1. Click OK to run the tool. The attachments are successfully exported in batch to the local folder defined in the Output Location parameter.
An image of the exported attachments in a folder.

ID d’article: 000011912

Recevoir des notifications et trouver des solutions liées à de nouvelles questions ou à des problèmes connus

Recevez des réponses synthétisées et des solutions en vidéo de notre nouvel agent conversationnel (IA).

Télécharger l’application Esri Support

Informations associées

En savoir plus sur ce sujet

Obtenir de l’aide auprès des experts ArcGIS

Contacter le support technique

Télécharger l’application Esri Support

Accéder aux options de téléchargement