Select to view content in your preferred language

Python Script From ArcGis Training.

878
1
04-23-2014 06:33 AM
BenjaminMittler
Frequent Contributor
I have been doing some of the python training from ESRI and i am running into a problem with one of the scripts they are having me use. The script is directly from the training page. From my understanding the reason that this won't work is that mapDoc isnt defined. Is it the training that has an error in it? The script updates layer files for a map.

>>> path = r"C:\Users\mittler_b\Desktop\Misc\MapScripting10_0\Maps\\"
... arcpy.env.workspace = path
... sourceLyr = arcpy.mapping.Layer(r"C:\Users\mittler_b\Desktop\Misc\MapScripting10_0\NewParks.lyr")
... for mapdoc in arcpy.ListFiles("*.mxd"):
...     print mapDoc
...     mxd = arcpy.mapping.MapDocument(path + mapDoc)
...     for df in arcpy.mapping.ListDataFrame(mxd):
...         updateLyr = arcpy.mapping.ListLayers(mxd, "Parks", df)[0]
...         arcpy.mapping.UpdateLayer(df, updateLyr, sourceLyr)
...     mxd.save()
Tags (2)
0 Kudos
1 Reply
JoshuaChisholm
Frequent Contributor
Good call Benjamin,

The is a typo in the script. The for loop sets up the variable as "mapdoc" and is later referred to as "mapDoc" (note the capital "D"). Variables in python are case sensitive. You should probably tell ESRI if this typo exists in the training.

Good luck!
0 Kudos