MakeXYEventLayer No Errors, but No Results

Discussion created by belowzero8 on Jan 4, 2011
Latest reply on Feb 22, 2012 by curtvprice
I am writing a python script that batch processes some creation of XY events based on csv tables.  The script is set up as a tool where the user provides 3 fields (the first two are needed to find the specific csv file and the second is the path to all of the csv data).  Anyway, when I run the tool it processes with no errors, but the XY Event Layer is not added to the proper data frame or the map at all.  However, when I run snippets of the code in the ArcMap python window it works and the event layer is added to the map appropriately. 

Here is the code, I tried to simplify it a bit:

import arcpy, sys
from arcpy import env

str1 = sys.argv[1]
str2 = sys.argv[2]
filesPath = sys.argv[3]
env.workspace = filesPath

# Update file path
filesPath +=  str1 + str2

# Set mxd file and get a list of data frames
mxd = arcpy.mapping.MapDocument("Current")
dfList = arcpy.mapping.ListDataFrames(mxd)

    # Loops through data frame and adds XY events for csv files
    for df in dfList:
        if == "2010":
            mxd.activeView = df
            fileTemp = filesPath
            fileTemp += + ".csv"
            outLayer = str1 + str2 + + "_XYEvents"
            arcpy.MakeXYEventLayer_management('"' + fileTemp + '"', "X", "Y", outLayer)

    print arcpy.GetMessages()

The weird thing is, if I try to run it again it tells me the file name already exists.  So it appears that it created the event layer, but it was just not added to the map.  I tried to use AddLayer, but python did not like that.