Select to view content in your preferred language

setting MapDocument.activeView causes existing layers to disappear

1396
5
03-25-2011 03:46 PM
EvanThoms
Frequent Contributor
I have one mxd with two data frames ['Layers', 'New Data Frame'] with layers in them. If Layers is active and I use the lines below in the command line window:

mxd = arcpy.mapping.MapDocument('Current')
df = arcpy.mapping.ListDataFrames(mxd, 'New Data Frame')[0]
mxd.activeView = df


New Data Frame is made active and I see the layers.

If use the same commands in a geoprocessing script, the layers are removed from the data frame before it is made active.

Does anyone know what's going on?
0 Kudos
5 Replies
JasonScheirer
Esri Alum
Do not change the active data frame in Geoprocessing scripts. Before a geoprocessing tool runs, it takes a snapshot of the active data frame's layers, and then restores it when it finishes executing. By changing the active data frame in between the snapshot and the restore, it gets into a confused state and may drop layers.
0 Kudos
JeffBarrette
Esri Regular Contributor
We reproduced this bug an will hopefully be able to address it in the next service pack.

If you want to check its status, it is: NIM066646
0 Kudos
EvanThoms
Frequent Contributor
Excellent! Thank you Jeffery.
0 Kudos
EvanThoms
Frequent Contributor
and Jason! Thank you for the explanation.
0 Kudos
JeffBarrette
Esri Regular Contributor
This issue will be addressed in service pack 3.
0 Kudos