Hello all,
I have ArcGIS Pro 3.0 notebook and python 27. I am not expertise with code. Please see error and code below. I exported from ArcGIS Pro notebook to Python script. It is working fine when run on ArcGIS Pro notebook. But when I tried to run Python script, I got an error message. I am not sure what to do. Please kindly assist. Thank you so much in advance.
PYTHON SCRIPT CODE
from arcgis.gis import GIS
import arcpy
import csv
import os
from datetime import date
from datetime import datetime
matchTableName = r"CertificatesAttachmentMatchTable.csv"
docFolder = r"Q:\2022\IMPORTED TO GIS"
matchField = "MatchID"
pathField = "Filename"
#change this date to the disired value
processFilesAddedOnDate = datetime. strptime('06/01/2022', '%m/%d/%Y')
#processFilesAddedOnDate = date.today()
# iterate through each .pdf file in the directory and write a row to the table
for (root, dirs, files) in os.walk(docFolder):
workingFolder = root
matchTableNamePath = os.path.join(root, matchTableName)
# create a new Match Table csv file
if os.path.exists(matchTableNamePath):
os.remove(matchTableNamePath)
writer = csv.writer(open(matchTableNamePath, "w", newline=''), delimiter=",")
# write a header row (the table will have two columns: ParcelID and Picture)
writer.writerow([matchField, pathField, 'fullPath'])
for f in files:
if '.pdf' in f:
if datetime.fromtimestamp(os.path.getctime(os.path.join(root, f))).strftime("%m/%d/%Y") >= processFilesAddedOnDate.strftime("%m/%d/%Y") :
fileNameToAddress = f.replace(".pdf", "")
fileNameToAddress = fileNameToAddress.replace(" ", " ");
fileNameToAddress = fileNameToAddress.replace("nw", "NW")
try:
firstPartUntilNW = fileNameToAddress.split("NW")[0].strip().split(" ")
restAfterNW = fileNameToAddress.split("NW")[1].strip()
#print(firstPartUntilNW, len(firstPartUntilNW))
#print(restAfterNW)
fileNameToAddressWithNoPermitNumber = ""
if len(firstPartUntilNW) == 2:
fileNameToAddressWithNoPermitNumber = firstPartUntilNW[1]+" NW "+restAfterNW
if len(firstPartUntilNW)== 1:
fileNameToAddressWithNoPermitNumber = firstPartUntilNW[0]+" NW "+restAfterNW
#print(fileNameToAddressWithNoPermitNumber)
writer.writerow((fileNameToAddressWithNoPermitNumber,f, os.path.join(root, f)))
except:
continue
del writer
arcpy.management.AddAttachments("sde.123.test", "ADDR", matchTableNamePath, "MatchID", "Filename", workingFolder)
ERROR MESSAGE
= RESTART: M:\test\ArcGIS\Projects\EC\IMPORTEC.py
Traceback (most recent call last):
File "M:\test\ArcGIS\Projects\EC\IMPORTEC.py", line 52, in <module>
arcpy.management.AddAttachments("sde.123.test", "ADDR", matchTableNamePath, "MatchID", "Filename", workingFolder)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 874, in AddAttachments
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 871, in AddAttachments
retval = convertArcObjectToPythonObject(gp.AddAttachments_management(*gp_fixargs((in_dataset, in_join_field, in_match_table, in_match_join_field, in_match_path_field, in_working_folder), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Dataset: Dataset sde.123.test does not exist or is not supported
Failed to execute (AddAttachments).