This question already has an answer here:
I am trying this simple task to add a feature class to an mxd (ArcGIS 10.3) but getting few errors. Here are two options I tried.
1) Preferred option - adding feature class itself into a active dataframe of the current mxd. I used the script below:
import arcpy mxd=arcpy.mapping.MapDocument("CURRENT") DF=mxd.activeDataFrame arcpy.mapping.AddLayer(DF,"C:\Work\GP1500\Tests\Input.gdb\Poly1","TOP")
The addLayer line generates the error below ...... assert isinstance(add_layer, Layer) AssertionError
2) Create a layer from the Feature class and add the layer using the script *****
import arcpy mxd=arcpy.mapping.MapDocument("CURRENT") DF=mxd.activeDataFrame FC="C:\Test.gdb\Test_Poly1" arcpy.MakeFeatureLayer_management(FC,"TestPolyLayer") inputlayer =arcpy.mapping.layer(TestPolyLayer) arcpy.mapping.AddLayer(DF,inputlayer,"TOP")
******It generates the error while executing the second last line i.e. to define input layer with following message AttributeError: 'module' object has no attribute 'layer'
Note: the second option i used is after I saw Nick's reply in How to add feature class to MXD with ArcPy (Python)?