I'm working through the recipes in the Python cookbook, and am having some weird results.
When I run the script (copied below) with
the map reference listed as "CURRENT" from an open mxd
from the Python window in Arcmap
I get the expected results -- a layer is added to the map.
However, when I:
- change the map reference to a path
- save the script as a .py, and
- run it from idle
no errors are thrown, but no layer is added. I even tried nesting the whole thing in a try/except/else statement, and I got back the else response.
I know the mxd path is correct, because I copied it from ArcCatalog.
# Import arcpy.mapping module import arcpy.mapping as mapping # Create a map reference mxd = mapping.MapDocument(r"H:\Python\Python_Cookbook\Maps\TravisCounty.mxd") # Create a reference to the primary data frame where the layer will be added df = mapping.ListDataFrames(mxd) # Define the reference layer refLayer = mapping.ListLayers(mxd, "Building_Permits*", df) # Define the layer to beinserted relative to the reference layer: insertLayer = mapping.Layer(r"H:\Python\Python_Cookbook\data\TravisCounty\School_District_2.lyr") # Insert the layer into the df mapping.InsertLayer(df,refLayer,insertLayer,"BEFORE")