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)
Solved! Go to Solution.
import arcpy csvDir = r"Path\To\Your\csvDirectory" shpDir = r"Path\To\Your\shp\output\csvDirectory" csvfiles = [os.path.join(csvDir, i) for i in os.listdir(csvDir) if i.endswith(".csv")] for file in csvfiles: arcpy.MakeXYEventLayer_management(file, "lonFieldName", "latFieldName", "temp_outlayer",arcpy.SpatialReference(4326)) arcpy.CopyFeatures_management("temp_outlayer",os.path.join(shpDir,os.path.basename(file))) arcpy.Delete_management("temp_outlayer")
mxd = arcpy.mapping.MapDocument(r"CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "*")[0] arcpy.env.workspace = shpDir shpList = arcpy.ListFeatureClasses() for featureClass in shpList: newLayer = arcpy.mapping.Layer(featureClass) arcpy.mapping.AddLayer(df,newLayer) del newLayer del mxd del df
import arcpy csvDir = r"Path\To\Your\csvDirectory" shpDir = r"Path\To\Your\shp\output\csvDirectory" csvfiles = [os.path.join(csvDir, i) for i in os.listdir(csvDir) if i.endswith(".csv")] for file in csvfiles: arcpy.MakeXYEventLayer_management(file, "lonFieldName", "latFieldName", "temp_outlayer",arcpy.SpatialReference(4326)) arcpy.CopyFeatures_management("temp_outlayer",os.path.join(shpDir,os.path.basename(file))) arcpy.Delete_management("temp_outlayer")
mxd = arcpy.mapping.MapDocument(r"CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "*")[0] arcpy.env.workspace = shpDir shpList = arcpy.ListFeatureClasses() for featureClass in shpList: newLayer = arcpy.mapping.Layer(featureClass) arcpy.mapping.AddLayer(df,newLayer) del newLayer del mxd del df
file = file.replace(" ","") file = file.replace("-","") file = file.replace(".txt","") print file
import arcpy, os csvDir = r"c:\avdata\FallChinookRedds\2013\moretextfiles" shpDir = r"c:\avdata\FallChinookRedds\2013\Shapefiles" csvfiles = [os.path.join(csvDir, i) for i in os.listdir(csvDir) if i.endswith(".txt")] for file in csvfiles: arcpy.MakeXYEventLayer_management(file, "LONG", "LAT", "temp_outlayer",arcpy.SpatialReference(4326)) #remove spaces, -, and .txt in file name file = file.replace(" ","") file = file.replace("-","") file = file.replace(".txt","") print file arcpy.CopyFeatures_management("temp_outlayer",os.path.join(shpDir,os.path.basename(file))) arcpy.Delete_management("temp_outlayer")
import arcpy, os mxd = arcpy.mapping.MapDocument(r"c:\avdata\FallChinookRedds\2013\fallchinook2013.mxd") print mxd df = arcpy.mapping.ListDataFrames(mxd, "*")[0] arcpy.env.workspace = r"c:\avdata\FallChinookRedds\2013\Shapefiles" shpList = arcpy.ListFeatureClasses() print shpList for featureClass in shpList: newLayer = arcpy.mapping.Layer(featureClass) arcpy.mapping.AddLayer(df,newLayer) del newLayer mxd.saveACopy(r"c:\avdata\FallChinookRedds\2013\fallchinook2013-2.mxd") del mxd del df