I was trying to add some pictures as attachments to my features in a feature class in a .mdb with ArcPy. I'm fairly new to this, so I was just playing with some test data and I modified the demo codes from ArcGIS tutorial like this:
# encoding: utf-8
import arcpy
import _csv
import os
import sys
arcpy.env.workspace = "F:/全国省级、地市级、县市级行政区划shp/全国省级、地市级、县市级行政区划shp/New Personal Geodatabase.mdb"
input = "F:/New Personal Geodatabase.mdb/Province"
inputField = "OBJECTID"
matchTable = r"F:\matchtable.csv"
matchField = "OBJECTID"
pathField = "Picture"
picFolder = r"F:\MGS"
writer = _csv.writer(open(matchTable, "wb"), delimiter=",")
writer.writerow([matchField, pathField])
for file in os.listdir(picFolder):
if str(file).find(".jpg") > -1:
writer.writerow([str(file).replace(".jpg", ""), file])
del writer
arcpy.EnableAttachments_management(input)
arcpy.AddAttachments_management(input, inputField, matchTable, matchField, pathField, picFolder)
(Because I'm Chinese, so the file name contained Chinese character. However, in other applications this file name worked with no problem)
Then I got error like this:
Traceback (most recent call last):
File "F:/���ֿμ���������/ʵϰ/ArcPy Sandbox/AutomateScript/BatchAddAttribute.py", line 29, in <module>
arcpy.AddAttachments_management(input, inputField, matchTable, matchField, pathField, picFolder)
File "F:\ArcGIS 10.2.1\Engine10.2\arcpy\arcpy\management.py", line 124, in AddAttachments
raise e
arcgisscripting.ExecuteError: ERROR 000228: Cannot open the dataset.
Failed to execute (AddAttachments).
ArcGIS version is 10.2
Any idea why?