启用附件 (Data Management)

许可等级:BasicStandardAdvanced

摘要

启用地理数据库要素类或表的附件。创建必要的附件关系类和将在内部存储附件文件的附件表。

用法

语法

EnableAttachments_management (in_dataset)
参数说明数据类型
in_dataset

将启用附件的地理数据库表或要素类。输入的表或要素类必须处于 10 或更高版本的地理数据库中。

Table View

代码实例

EnableAttachments 示例(Python 窗口)

以下代码片段说明了如何在 Python 窗口中使用 EnableAttachments 工具。

import arcpy
arcpy.EnableAttachments_management(r"C:\Data\City.gdb\Parcels")
EnableAttachments 示例(独立 Python 脚本)

以下脚本说明了如何在独立脚本中使用 EnableAttachments 工具。

"""
Example: we have a folder of digital photographs of vacant homes; the photos
are named according to the ParcelID of the house in the picture. Let's add
these photos to a parcel feature class as attachments.
"""

import csv
import arcpy
import os
import sys

input = r"C:\Data\City.gdb\Parcels"
inputField = "ParcelID"
matchTable = r"C:\Data\matchtable.csv"
matchField = "ParcelID"
pathField = "Picture" 
picFolder = r"C:\Pictures"

try:
    # create a new Match Table csv file
    writer = csv.writer(open(matchTable, "wb"), delimiter=",")

    # write a header row (the table will have two columns: ParcelID and Picture)
    writer.writerow([matchField, pathField])

    # iterate through each picture in the directory and write a row to the table
    for file in os.listdir(picFolder):
        if str(file).find(".jpg") > -1:
            writer.writerow([str(file).replace(".jpg", ""), file])

    del writer

    # the input feature class must first be GDB attachments enabled
    arcpy.EnableAttachments_management(input)

    # use the match table with the Add Attachments tool
    arcpy.AddAttachments_management(input, targetField, matchTable, matchField, pathField, picFolder)
except:
    print arcpy.GetMessages(2)

环境

相关主题

许可信息

ArcGIS for Desktop Basic:否
ArcGIS for Desktop Standard:是
ArcGIS for Desktop Advanced:是
9/15/2013