Select to view content in your preferred language

Making layers persist in TOC after python toolbox execution completes

2718
3
11-14-2014 04:44 AM
stevenbosher
Deactivated User

Hi,

I am on ArcGIS 10.1 SP1 (Build 3143)

I have a python toolbox that is producing a number of shapefile outputs that I would like to add to the ArcGIS TOC.

 

Problem I am having is that whilst the layers add to the TOC while the tool is running when it completes the layers are deleted, and I can't seem to find a way to avoid this.

 

Anybody have any ideas? My code (pretty standard) is below:

 

mxd = arcpy.mapping.MapDocument("CURRENT")

df  = arcpy.mapping.ListDataFrames(mxd."*")[0

addLayer = arcpy.mapping.Layer(outputFeatureclass)

arcpy.mapping.AddLayer(df, addLayer,"BOTTOM"

arcpy.RefreshTOC()

arcpy.RefreshActiveView()

 

Thanks for any help!

 

Steve

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

mxd.save()

and make sure that you haven't set your geoprocessing options to have results temporary by default

0 Kudos
stevenbosher
Deactivated User

Thanks Dan for your response.

Unfortunatly none of these work for me..

0 Kudos
SilviaP
Emerging Contributor

I have the same problem, could you solve it?

0 Kudos