I would like to take an empty group layer and add it an existing group layer within an MXD. The empty group layer does not currently exist , i am going to use an empty group layer i have saved within a folder.
i am using a list to build the layers i would like to create and then add.
The whole process consists of having order 1 groups , that contain sub groups.
i was able to do the first step , by creating the intial layers using the code below
Group_1 = ['Scotland','England','Wales','Spain']
for first_Group in Group_1:
mxd = arcpy.mapping.MapDocument(r"C:\GIS\PROJECT\PYTHON\GROUP_LAYER_TEMPLATE_copy.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
groupLayer = arcpy.mapping.Layer(r"C:\GIS\PROJECT\PYTHON\\An_empty_Group_Layer.lyr")
arcpy.mapping.AddLayer(df, groupLayer, "BOTTOM")
layers = arcpy.mapping.ListLayers(mxd)
for layer in layers:
if layer.isGroupLayer and layer.name == "An_empty_Group_Layer":
layer.name = first_Group
mxd.save()
Using the above Code , i was able to add the follwing group layers to the MXD
Scotland
England
Wales
Spain
I Like to use second list i have to create the second level of groups
Group_2 = [['Scotland','Aberdeen'],['Scotland','Glasgow'],['Scotland','Inverness'],['England','london']['England','bristol']['England','NewCastle'],['Wales',Cardiff],['Wales','Newport']
,['Wales','Swansea'],['Spain','Mardid],['Spain','Valencia'],['Spain','Barcelonia'],
i can use a loop to go through my Second group
That would allow me to add groups , i would need to find a way using the group name to tie into adult group
# An example item in the list ['Scotland','Aberdeen']
# The first element can be used track by to the group above. In this example it would return 'Scotland'. I would like to take this value and then use it to reference the group above.
for item in group_2:
# x equals the first element of the group
x = item[0]
#Can use the Second Value from the Item to be used to make the group name
for item in group_2:
# x Equals Aberdeen
x = item[1]