Select to view content in your preferred language

addlayer error!!

8886
22
08-06-2014 01:58 PM
LefterisKoumis
Frequent Contributor

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 lyr.name == "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.

0 Kudos
22 Replies
XanderBakker
Esri Esteemed Contributor

See also the solution provided in the other related thread:

https://community.esri.com/message/395539#395539

JamesCrandall
MVP Alum

My logic: if the ESRI system engineers decided to integrate the Default.gdb into the core of ArcGIS 10.x, then it might be a good idea to follow suit.

0 Kudos
XanderBakker
Esri Esteemed Contributor

According to James Fee we are still not there: The Shapefile‌, although I rarely use shapefiles anymore...

0 Kudos