2

I wanted to add a layer through the toolbox using arcpy. The below script works fine through the python console in ArcMap, but does not when executed through the toolbox. The layer flashes for a second in the layer management window and disappears. This looks very unlikely and I am not able to figure out how it could not work in the toolbox. Let me know if I had missed something.

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
sourceLayer = arcpy.mapping.Layer('C:/WIP/Shape files/KARTHIK.TEST_TABLE.lyr')
arcpy.mapping.AddLayer(df,sourceLayer,"TOP")
arcpy.RefreshActiveView()
asked Jun 18, 2012 at 9:05
0

1 Answer 1

5

What version / service pack do you have? It seems this problem was fixed recently in v10 SP1.

http://forums.arcgis.com/threads/8331-AddLayer-only-temporarily-adds-the-layer-to-map

You can try downloading SP1 here. http://resources.arcgis.com/content/patches-and-service-packs?fa=viewPatch&PID=66&MetaID=1685

answered Jun 18, 2012 at 9:21
1
  • I have been working with v10. Thanks for giving me the link let me try using the service pack 1 Commented Jun 19, 2012 at 2:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.