ArcMap crashes using "ExportXYv_stats" command in loop

240
3
11-22-2018 02:12 PM
EliseosMucaki
New Contributor III

I have written a script using ArcPy commands that, in short, randomly generates points in several areas, merges them, adds XY coordinates to the merged points, and exports them with the "ExportXYv_stats" command. This script works perfectly fine if I run it once. However, whenever I try to add a 'for loop' to do this several times, ArcMap v10.4 crashes after completing the "Export" command. No error is visible before the crash occurs. Example code:

for x in range(0, 3):

   ... (extraneous code)...

   arcpy.AddXY_management(merge_name)

   output_file = "Filename%d.txt" % x

   arcpy.ExportXYv_stats(merge_name,"FID", "COMMA",output_file,"ADD_FIELD_NAMES")  

The program crashes here. It will export the output file correctly, but the program completely halts afterwards (print statements placed immediately after the command do not get printed), and ArcMap crashes. If I comment out the export command, the program loops without issue. If I remove the loop, the program does not crash.

I am at a loss of why this would be happening. Any suggestions would be appreciated.  

0 Kudos
3 Replies
JoshuaBixby
MVP Esteemed Contributor

Sharing with Python‌ since this is an ArcPy question and not an ArcGIS API for Python question.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

How are you running this script?  In a tool, the interactive Python window in ArcMap, or outside of ArcMap completely?

0 Kudos
EliseosMucaki
New Contributor III

I am running it through the interactive Python window in ArcMap, using the "execfile(r'C:/path/program.py')" command.

FYI, I've tried the same code on a different machine (same version of ArcMap), and it crashed on that computer as well.

EDIT - to add to this, I tried running the program in two parts, one that created 100 sets of random points into 100 "merge" layers, and a second one that did the exporting step. No crash. Very strange, but at least I have a method to get the data that I need.

0 Kudos