arcpy mapping.mapDocument

المشرف العام

Administrator
طاقم الإدارة
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.

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")

أكثر...
 
أعلى