Every time I run this script now, I get an error on the line with the MakeFeatureLayer line. Sorry for all the questions! I'm really new to Python.

import arcpy, os

arcpy.env.workspace = r'C:\pathway to gdb'
fcs = arcpy.ListFeatureClasses()

mxd = arcpy.mapping.MapDocument(r'C:\pathway to mxd')
DF = arcpy.mapping.ListDataFrames(mxd,'*')[0]

for feature in fcs:
    inputlayer = 'C:\pathway to gdb' 
    outlayer = os.path.join(fcs, 'feature'+'.lyr')


    layer = arcpy.mapping.Layer(mxd)
  • can you run it from the "Python" window in ArcMap. I do that a lot with something like ... execfile(r"C:\myfolder\myfile.py") Mar 26, 2015 at 18:50
  • Does this question help? gis.stackexchange.com/q/21906/43 Mar 26, 2015 at 18:51
  • The question you posted Richard I had stumbled across before. However, how do you run this process in the foreground rather than the background? Also, this needs to be run in IDLE.
    – user48149
    Mar 26, 2015 at 19:39

1 Answer 1


Answer to your original question:

There is no "CURRENT" MXD when running outside of ArcMap. Use mxd = arcpy.mapping.MapDocument(r'C:\full\path\to.mxd') instead.

Answer to your edited question:

You can't create a Layer object from a MapDocument object (i.e. layer = arcpy.mapping.Layer(mxd)). Do something like this instead:

for fc in fcs:
    layer = arcpy.mapping.Layer(fc)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.