arcpy.MakeFeatureLayer_management(fc, fl, whereClause) outLayerFilePath = outputFL + "\\" + fl + ".lyr" # Save to Layer file arcpy.SaveToLayerFile_management(fl, outLayerFilePath) out_layer = arcpy.mapping.Layer(outLayerFilePath) # Line checks to ensure the feature layers were created with the right feature count #countFeatures = arcpy.GetCount_management(out_layer).getOutput(0) #print countFeatures arcpy.mapping.AddLayer(df, out_layer) arcpy.RefreshTOC() arcpy.RefreshActiveView() mxd.saveACopy(outputMXDpath) # only when this line is added to save to a new mxd can I see the newly added layers.
Solved! Go to Solution.
mxd = arcpy.mapping.MapDocument("CURRENT")
mxd = arcpy.mapping.MapDocument("CURRENT")
# Get your current MXD and DF (assuming you only have one df) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "*")[0] # Get a Layer refernce to the layer you want to add fc_mapping_reference = arcpy.mapping.Layer(fc) # Add your layer to your current df arcpy.mapping.AddLayer(df,fc_mapping_reference,"BOTTOM") # If you're having problems refreshing your screen arcpy.RefreshActiveView()