Skip to main content
deleted 6 characters in body; edited tags
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Referencing this question, Adding new group layer with ArcPy?, I'm trying to use python to add a empty group within a group layer. So far I'm able to add a empty group within the map document, however I'm getting an error when trying to add another empty group within the existing group layer. Here is the error message:

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 88, in AddLayerToGroup assert isinstance(target_group_layer, Layer) and target_group_layer._arc_object.isGroupLayer AssertionError

Here is my code:

        mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
        df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
        groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
        arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
        targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)
        addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
        arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM") # error here
        mxd.save()
        del mxd,df

Can you add empty group layers within an existing group (using v10.1 SP1)? The ESRI documentation (see image below) states that you can add .lyr to groups (maybe not a .lyr group layer?).

enter image description here

Thanks

UPDATE

 

Here is the working code (thanks to Jason Scheirer):

    mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
    arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
    targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)[0]
    addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
    arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")
    mxd.save()
    del mxd,df

Referencing this question, Adding new group layer with ArcPy?, I'm trying to use python to add a empty group within a group layer. So far I'm able to add a empty group within the map document, however I'm getting an error when trying to add another empty group within the existing group layer. Here is the error message:

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 88, in AddLayerToGroup assert isinstance(target_group_layer, Layer) and target_group_layer._arc_object.isGroupLayer AssertionError

Here is my code:

        mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
        df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
        groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
        arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
        targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)
        addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
        arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM") # error here
        mxd.save()
        del mxd,df

Can you add empty group layers within an existing group (using v10.1 SP1)? The ESRI documentation (see image below) states that you can add .lyr to groups (maybe not a .lyr group layer?).

enter image description here

Thanks

UPDATE

Here is the working code (thanks to Jason Scheirer):

    mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
    arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
    targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)[0]
    addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
    arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")
    mxd.save()
    del mxd,df

Referencing this question, Adding new group layer with ArcPy?, I'm trying to use python to add a empty group within a group layer. So far I'm able to add a empty group within the map document, however I'm getting an error when trying to add another empty group within the existing group layer. Here is the error message:

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 88, in AddLayerToGroup assert isinstance(target_group_layer, Layer) and target_group_layer._arc_object.isGroupLayer AssertionError

Here is my code:

        mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
        df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
        groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
        arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
        targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)
        addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
        arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM") # error here
        mxd.save()
        del mxd,df

Can you add empty group layers within an existing group (using v10.1 SP1)? The ESRI documentation (see image below) states that you can add .lyr to groups (maybe not a .lyr group layer?).

enter image description here

 

Here is the working code (thanks to Jason Scheirer):

    mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
    arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
    targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)[0]
    addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
    arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")
    mxd.save()
    del mxd,df
replaced http://gis.stackexchange.com/ with https://gis.stackexchange.com/
Source Link

Referencing this question, Adding new group layer with ArcPy?Adding new group layer with ArcPy?, I'm trying to use python to add a empty group within a group layer. So far I'm able to add a empty group within the map document, however I'm getting an error when trying to add another empty group within the existing group layer. Here is the error message:

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 88, in AddLayerToGroup assert isinstance(target_group_layer, Layer) and target_group_layer._arc_object.isGroupLayer AssertionError

Here is my code:

        mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
        df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
        groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
        arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
        targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)
        addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
        arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM") # error here
        mxd.save()
        del mxd,df

Can you add empty group layers within an existing group (using v10.1 SP1)? The ESRI documentation (see image below) states that you can add .lyr to groups (maybe not a .lyr group layer?).

enter image description here

Thanks

UPDATE

Here is the working code (thanks to Jason Scheirer):

    mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
    arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
    targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)[0]
    addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
    arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")
    mxd.save()
    del mxd,df

Referencing this question, Adding new group layer with ArcPy?, I'm trying to use python to add a empty group within a group layer. So far I'm able to add a empty group within the map document, however I'm getting an error when trying to add another empty group within the existing group layer. Here is the error message:

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 88, in AddLayerToGroup assert isinstance(target_group_layer, Layer) and target_group_layer._arc_object.isGroupLayer AssertionError

Here is my code:

        mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
        df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
        groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
        arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
        targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)
        addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
        arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM") # error here
        mxd.save()
        del mxd,df

Can you add empty group layers within an existing group (using v10.1 SP1)? The ESRI documentation (see image below) states that you can add .lyr to groups (maybe not a .lyr group layer?).

enter image description here

Thanks

UPDATE

Here is the working code (thanks to Jason Scheirer):

    mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
    arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
    targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)[0]
    addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
    arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")
    mxd.save()
    del mxd,df

Referencing this question, Adding new group layer with ArcPy?, I'm trying to use python to add a empty group within a group layer. So far I'm able to add a empty group within the map document, however I'm getting an error when trying to add another empty group within the existing group layer. Here is the error message:

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 88, in AddLayerToGroup assert isinstance(target_group_layer, Layer) and target_group_layer._arc_object.isGroupLayer AssertionError

Here is my code:

        mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
        df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
        groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
        arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
        targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)
        addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
        arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM") # error here
        mxd.save()
        del mxd,df

Can you add empty group layers within an existing group (using v10.1 SP1)? The ESRI documentation (see image below) states that you can add .lyr to groups (maybe not a .lyr group layer?).

enter image description here

Thanks

UPDATE

Here is the working code (thanks to Jason Scheirer):

    mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
    arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
    targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)[0]
    addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
    arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")
    mxd.save()
    del mxd,df
Put the [0] in the right place--after the listlayers call.
Source Link

Referencing this question, Adding new group layer with ArcPy?, I'm trying to use python to add a empty group within a group layer. So far I'm able to add a empty group within the map document, however I'm getting an error when trying to add another empty group within the existing group layer. Here is the error message:

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 88, in AddLayerToGroup assert isinstance(target_group_layer, Layer) and target_group_layer._arc_object.isGroupLayer AssertionError

Here is my code:

        mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
        df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
        groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
        arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
        targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)
        addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
        arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM") # error here
        mxd.save()
        del mxd,df

Can you add empty group layers within an existing group (using v10.1 SP1)? The ESRI documentation (see image below) states that you can add .lyr to groups (maybe not a .lyr group layer?).

enter image description here

Thanks

UPDATE

Here is the working code (thanks to Jason Scheirer):

    mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
    arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
    targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)[0]
    addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
    arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")[0]
    mxd.save()
    del mxd,df

Referencing this question, Adding new group layer with ArcPy?, I'm trying to use python to add a empty group within a group layer. So far I'm able to add a empty group within the map document, however I'm getting an error when trying to add another empty group within the existing group layer. Here is the error message:

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 88, in AddLayerToGroup assert isinstance(target_group_layer, Layer) and target_group_layer._arc_object.isGroupLayer AssertionError

Here is my code:

        mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
        df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
        groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
        arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
        targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)
        addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
        arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM") # error here
        mxd.save()
        del mxd,df

Can you add empty group layers within an existing group (using v10.1 SP1)? The ESRI documentation (see image below) states that you can add .lyr to groups (maybe not a .lyr group layer?).

enter image description here

Thanks

UPDATE

Here is the working code (thanks to Jason Scheirer):

    mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
    arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
    targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)
    addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
    arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")[0]
    mxd.save()
    del mxd,df

Referencing this question, Adding new group layer with ArcPy?, I'm trying to use python to add a empty group within a group layer. So far I'm able to add a empty group within the map document, however I'm getting an error when trying to add another empty group within the existing group layer. Here is the error message:

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 88, in AddLayerToGroup assert isinstance(target_group_layer, Layer) and target_group_layer._arc_object.isGroupLayer AssertionError

Here is my code:

        mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
        df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
        groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
        arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
        targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)
        addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
        arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM") # error here
        mxd.save()
        del mxd,df

Can you add empty group layers within an existing group (using v10.1 SP1)? The ESRI documentation (see image below) states that you can add .lyr to groups (maybe not a .lyr group layer?).

enter image description here

Thanks

UPDATE

Here is the working code (thanks to Jason Scheirer):

    mxd = arcpy.mapping.MapDocument(r"C:\Temp\test.mxd")
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    groupLayer = arcpy.mapping.Layer(r"C:\Temp\Group.lyr")
    arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
    targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group", df)[0]
    addLayer = arcpy.mapping.Layer(r"C:\Temp\Group2.lyr")
    arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")
    mxd.save()
    del mxd,df
Updated for 2014
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Loading
clarified title
Link
blah238
  • 35.9k
  • 8
  • 96
  • 200
Loading
added 87 characters in body
Source Link
artwork21
  • 35.2k
  • 8
  • 67
  • 134
Loading
added 59 characters in body
Source Link
artwork21
  • 35.2k
  • 8
  • 67
  • 134
Loading
Source Link
artwork21
  • 35.2k
  • 8
  • 67
  • 134
Loading