Select to view content in your preferred language

Got Error when ran python - Exported from ArcGIS Pro Notebook to Python Script

1367
4
Jump to solution
02-10-2023 10:01 AM
AlexP_
by
Frequent Contributor

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

 

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

Add Attachments (Data Management)—ArcGIS Pro | Documentation

The error is specific

arcpy.management.AddAttachments(in_dataset, in_join_field, in_match_table, in_match_join_field, in_match_path_field, {in_working_folder})

6 parameters, the first 5 required and the last optional.... check your inputs to the tool.

 


... sort of retired...

View solution in original post

4 Replies
DanPatterson
MVP Esteemed Contributor

try providing the full path to sde.GIS.test on line 53


... sort of retired...
AlexP_
by
Frequent Contributor

@DanPatterson  Thank you for your prompt response. I ran it again and I got another error message below. I don't think I wrote the fullpath correctly.

I am trying to set up using python scrip to set up in task scheduler. is it possible to set up ArcGIS Pro Notebook to window task scheduler? the goal is to have it run by task scheduler. Please kindly advise.

 

= RESTART: M:\test\ArcGIS\Projects\EC\IMPORTEC.py
Traceback (most recent call last):
File "M:\test\ArcGIS\Projects\EC\IMPORTEC.py", line 53, in <module>
arcpy.management.AddAttachments(r"C:\Users\AppData\Roaming\Esri\ArcGISPro\Favorites\test.sde", "sde.123.test", "ADDR", matchTableNamePath, "MatchID", "Filename", workingFolder)
TypeError: AddAttachments() takes from 0 to 6 positional arguments but 7 were given
>>>

0 Kudos
DanPatterson
MVP Esteemed Contributor

Add Attachments (Data Management)—ArcGIS Pro | Documentation

The error is specific

arcpy.management.AddAttachments(in_dataset, in_join_field, in_match_table, in_match_join_field, in_match_path_field, {in_working_folder})

6 parameters, the first 5 required and the last optional.... check your inputs to the tool.

 


... sort of retired...
AlexP_
by
Frequent Contributor

@DanPatterson  Thank you for the information. I tried this method and it doesn't work. I found a different method for sde file workspace location added above line "acrpy.management.addattachments" and it was successful. 

# Set the workspace environment and run add attachment
    arcpy.env.workspace = r'C:\Users\AppData\Roaming\Esri\ArcGISPro\Favorites\test.sde'

 

0 Kudos