Convert Coordinate Notation Script: ExecuteError: ERROR 999999

12-29-2021 08:09 PM
New Contributor

I am using ArcGIS Pro 2.9 and Python 3.

I am trying to create a script to extract MGRS coordinates from PDFs, write those coordinates to an excel file, and then use the Convert Coordinate Notation script to create points. Ideally, this script will be used to routinely check for newly added PDFs and update the excel and point accordingly. I am receiving the error below and am not sure why. However, when I execute the Convert Coordinate Notation script separately on the same excel file, it is successful.  Thank you in advance for your help!

ExecuteError                              Traceback (most recent call last)
In  [42]:
Line 139:   arcpy.ConvertCoordinateNotation_management(formattedSheetName, out_points, "COORDINATE", "#", "MGRS", "DD_1")

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\, in ConvertCoordinateNotation:
Line 13029: raise e

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\, in ConvertCoordinateNotation:
Line 13026: retval = convertArcObjectToPythonObject(gp.ConvertCoordinateNotation_management(*gp_fixargs((in_table, out_featureclass, x_field, y_field, input_coordinate_format, output_coordinate_format, id_field, spatial_reference, in_coor_system, exclude_invalid_records), True)))

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\, in <lambda>:
Line 512:   return lambda *args: val(*gp_fixargs(args, True))

ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support ( to Report a Bug, and refer to the error help for potential solutions or workarounds.
Failed to execute (ConvertCoordinateNotation).
import PyPDF2, os, json, re, openpyxl, datetime, arcpy

#directory containing .pdf
directory = r'<file_path>' 

#Regex Objects
mgrs = r'\d{2}\D{1}\s?\D{2}?\s?\d{4,5}\s?\d{4,5}'
geo = r'\d{6}\D\s?\d{7}\D'

#set ArcGIS variables
in_table = r'<file_path>\<excel.xlsx>'
out_points = r'<file_path\<gdb_name>.gdb\<feature_class_name>'

#List to hold all Regex Objects
regexList = [mgrs, geo]

#List that holds all .pdf in a directory
new_files = [x for x in os.listdir(directory) if x.endswith('.pdf')]

saved_coords = r'<file_path>\<json_file.json>'

#temporary dictionary to hold previously unsearched files
temp_dict = {}

#character to be removed after extracting .pdf text
value = '\n'

#load dict1 from .json
    with open(saved_coords, 'r+') as f:
        dict1 = json.load(f)
    print('Dictionary successfully loaded')

#create dict1 if try failed
except Exception:
    dict1 = {}
    print('Unable to load dictionary. One was created.')

#iterates through all .pdf in directory and creates absolute file path
while new_files:
    current_file = new_files.pop()
    fullpath = os.path.join(directory, current_file)

    #open each .pdf file in drectory
    with open(fullpath, 'rb') as pdf:
        reader = PyPDF2.PdfFileReader(fullpath)
        #temp list and string to hold text from .pdf
        text_list = []
        pdf_text = ""

        #extracts text from each .pdf and appends it to pdf_text
        for i in range(reader.numPages):
            page = reader.getPage(i)
            text = page.extractText()
            text_list += text

            #remove \n characters that are added when extracting .pdf text
            while value in text_list:

        #appends .pdf_text with extracted text
        for i in text_list:
            pdf_text += i
        #iterates through regex objects list and checks each .pdf text for     them
        for x in regexList:
            if re.findall(x, pdf_text):
                mo = re.findall(x, pdf_text)

                #if mo found, filename and list of mo added to dict1 and temp
                #dict to be searched
                if current_file not in dict1:
                    temp_dict[current_file] = []
                    dict1[current_file] = []
                    temp_dict[current_file] += mo
                    dict1[current_file] += mo

#save updated dict1
with open(saved_coords, 'w+') as f:
    json.dump(dict1, f)

#attempt to load .xlsx
    wb = openpyxl.load_workbook(in_table)

#create .xlsx if one was not loaded
except Exception:
    wb = openpyxl.Workbook()

#create sheet in .xlsx at index 0
title =
sheet_title = title.strftime('%Y_%m_%d')

#get active sheet
sheet =

#create the titles for each column
sheet['A1'] = 'TITLE'
sheet['B1'] = 'COORDINATE'
sheet['C1'] = 'LAT'
sheet['D1'] = 'LONG'

#holds number for total mo found in searched .pdf's. determines how many rows are
#needed in .xlsx
num = 0

#holds keys to be appended to .xlsx next to coordinate
keys = []

#holds coordinates to be appended to .xlsx
coordinates = []

#determines how many rows are needed (one per mo)
for key, value in temp_dict.items():
    num += len(value)
    print_key = len(value)
    keys += print_key * [key.replace('.pdf','')]
    coordinates += value

#assigns file name to column A
for row in range(2,num+2):
    cell = sheet.cell(row=row, column=1)
    cell.value = keys.pop()
#assign mo (coordinates) to column B
for row in range(2,num+2):
    cell = sheet.cell(row=row, column=2)
    cell.value = coordinates.pop()

#saves .xlsx

#matches the formating required for arcpy convertCoordinateNotation script
formattedSheetName = f'{in_table}\T_{sheet_title}$_'

#call Convert Coordinate Notation with MGRS as input field.
#leaving out spatial reference parameter will default to WGS 1984 
arcpy.ConvertCoordinateNotation_management(formattedSheetName, out_points, "COORDINATE", "#", "MGRS", "DD_1")


0 Kudos
2 Replies
MVP Esteemed Contributor

what are the values for formattedSheetName, out_points ? (eg . add a print/AddMessage statement) since your required/positional parameters seem to be in order

... sort of retired...
0 Kudos
New Contributor

I found what was causing the error. I was leaving out the project file name in the out_points file path.. Thank you for responding though.

0 Kudos