I have a geodatabase with several feature dataset and feature classes associated with it respectively. I would like to create a .mxd where the Table of contents consist of group layer and each group layer has several shapefile. The group layer name should be same as Feature dataset name.The feature classes in each feature dataset comes shapefiles with in that particular group layer as shown in figure.

enter image description here

  • 1
    What version of ArcGIS? – user2856 Sep 24 '14 at 23:28

The following code snippet works in ArcGIS 10.1+.

Note that creating a new mxd can't be done in arcpy, you need to reference an existing empty mxd. Also, I couldn't find a way of creating a new empty group layer in arcpy, so I created one in ArcMap and saved it to a .lyr file and used that in the code.

import os,arcpy

template_mxd = r'C:\Temp\empty.mxd'
template_group_layer = r'C:\Temp\empty_group.lyr'
output_mxd = r'C:\Temp\not_empty.mxd'

df = arcpy.mapping.ListDataFrames(mxd)[0]
for path, dirs, files in arcpy.da.Walk(gdb):
    #Any "folder" in a GDB is a Feature Dataset 
    #and there can only be a single level
    for d in dirs: 
        #Add an empty group layer to ArcMap

    for f in files:
        if dsc.dataType == 'FeatureClass':
        elif dsc.dataType == 'RasterDataset':
        elif dsc.dataType == 'Table':

        if path==gdb and lyr:
        elif view:
            arcpy.mapping.AddTableView(df, view)
            arcpy.mapping.AddLayerToGroup(df, groups[d], lyr, "BOTTOM")


Results from above mentioned code

  • gis.stackexchange.com/a/4684/115 agrees with your workaround for "creating a new empty group layer in arcpy". – PolyGeo Sep 25 '14 at 4:34
  • Luke, This script works great in importing all the feature classes from several different feature datasets of a geodatabase. But if you see the picture in the question, I have clearly mention that for each feature dataset in a geodatabase, i need to create a group layer and the feature classes of each feature dataset comes under each group layer as shown in the figure. As pet the image , I have created a empty group layer but still the feature does not came under the group layer. Can you please try at your end. – user37082 Sep 30 '14 at 20:40
  • 2
    @PrashantKuranjekar Please note that you are undermining the usefulness of this page by asking the author to contact you in private. – underdark Sep 30 '14 at 20:54
  • Welcome to the site @Prashant Kuranjekar. Please note that I edited your comment to remove your private request for information. This site is an open forum and, therefore, all responses should be open and available to the public. Please read the information on posting questions at our help center: gis.stackexchange.com/help – Aaron Sep 30 '14 at 20:55
  • Fine with me....I just wanted to send him screen shots...Waiting for your response Luke!! – user37082 Sep 30 '14 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy