I just got handed 30 comma delimited txt files from someone's old GPS unit and asked if I could put them on a map for their report due tomorrow. Sure, I could plow through these files one at a time, import the txt files to ArcMap, display XY data, convert to a feature class, and make the deadline. But wouldn't it be more fun and elegant to loop through all the txt files with a python script? Might not save any time, but I might learn something and I'd prefer to miss the deadline to teach these people that their lack of planning does not make my emergency.
But I've already run into a problem. Although I can add these txt files with the ArcMap Add data button, I haven't been able to get AddLayer to add a txt file. Is it possible? Or is some other method used?
What I tried in the python window was
but just got a bunch of red runtime error stuff, nothing added to the map document. Don't know if I have a syntax error for the python window or AddLayer is not going to work with the txt file.
But I've already run into a problem. Although I can add these txt files with the ArcMap Add data button, I haven't been able to get AddLayer to add a txt file. Is it possible? Or is some other method used?
What I tried in the python window was
Code:
mxd = arcpy.mapping.MapDocument("CURRENT")
addLayer = (r"C:\avdata\FallChinookRedds\2013\cent2don 10-14-13.txt")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
arcpy.mapping.AddLayer(df, addLayer)