HOW TO

Exportieren von Anlagen mittels Batch-Export aus einer Feature-Class in ArcMap

Last Published: July 21, 2023

Zusammenfassung

ArcGIS Pro provides the capability to export attachments from a feature class by saving the attached file to a file system, as described in ArcGIS Pro: Save an attachment. However, this capability is limited to saving the attachments of only one feature at a time. There is no geoprocessing tool for users to export or save attachments to all features in one process.

The instructions provided describe a method to batch export attachments from a feature class by creating a script tool.

Note:
The workflow requires a Desktop Standard or Desktop Advanced license.

Vorgehensweise

To batch export attachments from a feature class in ArcGIS Pro, create a script tool from a Python script that enables exporting attachments in batches from a feature class. Run the script tool by providing the parameters required.

Note:
The script provided requires the standard attachment table, which is created when attachments are enabled as the input on a feature class. This is because it relies on the DATA, ATT_NAME and ATTACHMENTID fields stored in the table. A typical naming convention is to append _ATTACH to the end of the table name.
  1. Copy and paste the following script into a Notepad, and save it as ExportAttachments.py.
Note:
The following script iterates through the entire attachment table of a single feature class and copies the attachments (saved as BLOBs or binary large objects) to a file.
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
  1. In ArcGIS Pro, right-click a toolbox in the Catalog pane, and click New > Script
The steps to create a new script tool in the Catalog pane
  1. In the New Script window, set the properties of the script tool as follows:
    1. On the General tab, type the Name and Label for the script tool. For example, type ExportAttachments as the Name, and Export Attachments as the Label. The label displays the name of the script tool, as shown in the Geoprocessing pane.
    2. Check the Store tool with relative path check box.
    3. On the Parameters tab, type Attachments Table in the first row of the Label column, and set the Data Type as Table. This is the first parameter of the script tool and it defines the table containing the attachments to export.
    4. In the second row, add a second parameter with the Label name as Output Location, and set the Data Type as Folder. This parameter defines the folder to locate the exported attachments.
Configure the properties for the new script tool.
  1. On the Execution tab, click the Browse icon The Browse icon next to the Script File field, and navigate to the location of the script file saved in Step 1. Select the script and click OK.
  2. Click OK. A new script tool is added to the toolbox.
The created Export Attachments script tool.
  1. Double-click to open the created script tool. Set the parameters of the tool as follows to export the attachments in a batch.
    1. In the tool dialog box, browse for the attachments table containing the attachments to export in the Attachments Table parameter.
    2. In the Output Location parameter, select a folder to save the exported attachments, and click OK.
    3. Click Run.
The Export Attachments tool dialog box.

The attachments are successfully exported in a batch, and located in the folder defined in the Output Location parameter.

A list of the exported attachments in the location of the Output Location parameter

Artikel-ID:000017450

Hilfe von ArcGIS-Expert*innen erhalten

Technischen Support kontaktieren

Die Esri Support-App herunterladen

Zu den Download-Optionen

Zugehörige Informationen

Weitere Informationen zu diesem Thema erkunden