HowTo:  Batch export attachments from a feature class

相关信息
Article ID: 41763
Software:
ArcGIS - ArcEditor 10
ArcGIS - ArcInfo 10
ArcGIS - ArcView 10
ArcGIS for Desktop Advanced 10.1, 10.2
ArcGIS for Desktop Standard 10.1, 10.2
ArcGIS for Desktop Basic 10.1, 10.2
Platforms:
Windows Vista, Server 2008, Windows 7, Windows 8, Server 2012

问题描述
There are no geoprocessing tools that allow users to export and save all attachments locally. The instructions provided below describe a possible solution.

The following 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 file.
已邀请:

易智瑞技术支持

赞同来自:

解决方案
This script requires the input table to be the standard attachment table created when attachments are enabled on a feature class. This is because the below 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.

0. 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

  1. Open ArcCatalog and create a new toolbox.
  2. Right-click the toolbox and select Add > Script.
  3. Give the script a name and a label. Check the box next to Store relative path names, and click Next.
  4. For the script file, navigate to where the ExportAttachments.py script is saved. Select the script, click OK and click Next.
  5. Under Parameters, type 'Attachments Table' under Display Name and set its data type as Table. Add a second parameter and type 'Output Location' under display name and select Folder for its data type.
  6. Click Finish.
  7. A new script tool should now be added to the toolbox.
  8. Double-click the script tool. In the dialog, choose the attachments table that contains the attachments to be extracted for the first parameter. Choose a folder to save the exported attachments to under OutputLocation. Click OK to run the tool.


创建及修改时间
Created: 11/4/2013

Last Modified: 10/27/2014
原文链接
http://support.esri.com/en/kno ... 41763

要回复问题请先登录注册