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)...
output_file = "Filename%d.txt" % x
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.
How are you running this script? In a tool, the interactive Python window in ArcMap, or outside of ArcMap completely?
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.