AnsweredAssumed Answered

ValueError with DataFrame in arcpy.mapping.AddLayerToGroup

Question asked by peterlen on Aug 1, 2014
Latest reply on Aug 2, 2014 by peterlen

I am using ArcGIS 10.1 and am using Python to try to add a layer (.lyr file) to a group layer.  What I have is this:


mxd = arcpy.mapping.MapDocument(NEW_MXD)

dataFrame = arcpy.mapping.ListDataFrames(mxd)[0]


# Add group layer

groupLayer = arcpy.mapping.Layer(r"EmptyGroupLayer.lyr")

arcpy.mapping.AddLayer(dataFrame, groupLayer, "TOP")


# Add layer to group layer

tmpLayer = arcpy.mapping.Layer(r"zipcodes.lyr")

arcpy.mapping.AddLayerToGroup(dataFrame, groupLayer, tmpLayer, "BOTTOM")


I verified that the "groupLayer" is a group layer and tmpLayer is not.  I get the following error from a stack trace when the AddLayerToGroup is executed:


Error: DataFrameObject: Unexpected error

Traceback (most recent call last):

  File "", line 78, in <module>


  File "", line 46, in main

    arcpy.mapping.AddLayerToGroup(dataFrame, groupLayer, tmpLayer, "BOTTOM")

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\", line 18

1, in fn_

    return fn(*args, **kw)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\", line

93, in AddLayerToGroup

    data_frame._arc_object.InsertLayer(target_group_layer._arc_object, my_copy,


ValueError: DataFrameObject: Unexpected error



Not sure what I am missing as I feel that I am following the same process as other examples I have seen on the web.


Any thoughts on what the value error for the data frame might be?


Thanks - Peter