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)
try:
# Loops through data frame and adds XY events for csv files
for df in dfList:
if df.name == "2010":
mxd.activeView = df
fileTemp = filesPath
fileTemp += df.name + ".csv"
outLayer = str1 + str2 + df.name + "_XYEvents"
arcpy.MakeXYEventLayer_management('"' + fileTemp + '"', "X", "Y", outLayer)
except:
print arcpy.GetMessages()
import arcpy
from arcpy import env
from arcpy import mapping
env.workspace = r"C:\TEMP\Python\test.gdb"
env.overwriteOutput = 1
table = "XY"
#Make XY event layer
arcpy.MakeXYEventLayer_management(table, "X", "Y", "XY_event")
#Save XY event to a layer file
arcpy.SaveToLayerFile_management("XY_event", r"C:\temp\Python\XY_event.lyr")
#Add layer file to MXD
mxd = mapping.MapDocument(r"C:\temp\python\Airports.mxd")
for df in mapping.ListDataFrames(mxd):
lyr = mapping.Layer(r"C:\temp\python\XY_event.lyr")
mapping.AddLayer(df, lyr)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
mxd.save()
del lyr, mxd, df
arcpy.MakeXYEventLayer_management('"' + fileTemp + '"', "X", "Y", outLayer)
arcpy.MakeXYEventLayer_management(fileTemp, "X", "Y", outLayer)