AnsweredAssumed Answered

addlayer error!!

Question asked by lkoumis on Aug 6, 2014
Latest reply on Aug 8, 2014 by xander_bakker
Branched to a new discussion

I am new in python but this script should be easy to process. Instead I get:

arcpy.mapping.AddLayer(myDF,addlayer) NameError: name 'addlayer' is not defined


Here is the script:


import arcpy

thisMap = arcpy.mapping.MapDocument("CURRENT")

myDF = arcpy.mapping.ListDataFrames(thisMap)[0]

myLayers = arcpy.mapping.ListLayers(myDF)

for lyr in myLayers:

    if == "CNNDB":

      addlayer = arcpy.mapping.Layer(lyr)

      print "got it"


arcpy.mapping.AddLayer(myDF,addlayer,"AUTO ARRANGE")

arcpy.CreateFolder_management(r"D:\GIS_data", "test")

arcpy.mapping.ExportToPDF(thisMap, r"D:\GIS_data\test\Project.pdf",300,"BEST",layers_attributes="LAYERS_AND_ATTRIBUTES")


#Do you see any errors?  Thank you.