AnsweredAssumed Answered

Adding a shapefile to a blank .mxd in Arcpy

Question asked by brgionta on Feb 29, 2016
Latest reply on Feb 29, 2016 by dkwiens

How can you add several shapefiles to a blank .mxd using a script written with Arcpy? I've started with the code below. The code runs with no errors but the shapefile is not added to the blank .mxd. I'm not sure if you have to first convert the shapefiles to .lyr files? I am trying to run the script outside of ArcMap in command line window.


import arcpy
from arcpy import env

# get the map document
= arcpy.mapping.MapDocument("CURRENT")

# get the data frame
= arcpy.mapping.ListDataFrames(mxd,"*")[0]

# create a new layer
= arcpy.mapping.Layer(path_to_shapefile_or_feature_class)

# add the layer to the map at the bottom of the TOC in data frame 0
.mapping.AddLayer(df, newlayer,"BOTTOM")