I'm having a bit of a problem with a script on a particular machine.
==========================================================
import arcpy,sys
class AddLayer(object):
'''
classdocs
'''
def __init__(self,sNewHabFile,workspace):
scriptPath = sys.path[0]
f = file(scriptPath + chr(92) +'AddLayerFile_ArcGIS_log.txt', 'w') # open for 'w'riting
f.write("Add layer file initialised") # write text to file
f.write("\n")
layerFile = sNewHabFile + ".lyr"
f.write(str(layerFile)) # write text to file
f.write("\n")
mxd = arcpy.mapping.MapDocument("CURRENT")
f.write(str(mxd.filePath)) # write text to file
f.write("\n")
addLayer = arcpy.mapping.Layer(layerFile)
f.write(str(addLayer.name)) # write text to file
f.write("\n")
df = arcpy.mapping.ListDataFrames(mxd)[0]
f.write(str(df.name)) # write text to file
f.write("\n")
arcpy.mapping.AddLayer(df, addLayer, "TOP")
f.write("Layer added?") # write text to file
f.write("\n")
layer = arcpy.mapping.ListLayers(mxd)[0]
f.write("First layer is called:" + str(layer.name)) # write text to file
f.write("\n")
arcpy.RefreshTOC()
'''
end
'''
============================================================
It's working fine on my machine, but testing the whole tool on another machine, AddLayer here and in another module I have written does not throw up an error, it just doesn't add the final outputs to the map.
As you can see above I have writen to a text file and
layer = arcpy.mapping.ListLayers(mxd)[0]
and
f.write("First layer is called:" + str(layer.name))
are writing the correct layer to the text document, but I can't see anything in the TOC.
I can manually add the created data.
On my original machine, which is working I am running:
ArcView single use with Spatial Analyst, 4th or 5th service pack I think.
The machine that is not working is running ArcEditor concurrent with access to Spatial Analyst, this is likely to be a much earlier service pack (either none or 1 or 2).
Does anyone have any ideas?