I'm working through the recipes in the Python cookbook, and am having some weird results.
When I run the script (copied below) with
However, when I:
I know the mxd path is correct, because I copied it from ArcCatalog.
Any ideas?
# Import arcpy.mapping moduleimport arcpy.mapping as mapping# Create a map referencemxd = mapping.MapDocument(r"H:\Python\Python_Cookbook\Maps\TravisCounty.mxd")# Create a reference to the primary data frame where the layer will be addeddf = mapping.ListDataFrames(mxd)[0]# Define the reference layerrefLayer = mapping.ListLayers(mxd, "Building_Permits*", df)[0]# 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 dfmapping.InsertLayer(df,refLayer,insertLayer,"BEFORE")
أكثر...
When I run the script (copied below) with
- the map reference listed as "CURRENT" from an open mxd
- from the Python window in Arcmap
However, when I:
- change the map reference to a path
- save the script as a .py, and
- run it from idle
I know the mxd path is correct, because I copied it from ArcCatalog.
Any ideas?
# Import arcpy.mapping moduleimport arcpy.mapping as mapping# Create a map referencemxd = mapping.MapDocument(r"H:\Python\Python_Cookbook\Maps\TravisCounty.mxd")# Create a reference to the primary data frame where the layer will be addeddf = mapping.ListDataFrames(mxd)[0]# Define the reference layerrefLayer = mapping.ListLayers(mxd, "Building_Permits*", df)[0]# 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 dfmapping.InsertLayer(df,refLayer,insertLayer,"BEFORE")
أكثر...