<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create and populate group layers with feature classes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-and-populate-group-layers-with-feature/m-p/1357589#M69342</link>
    <description>&lt;P&gt;It's a painful task to do!&lt;BR /&gt;Thank you so much, the first try worked to create a group layer and populate it.&lt;BR /&gt;I need to continue working on it as the code requires to create of multi-group layers and adding layers in different folders based on their names!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Dec 2023 19:11:16 GMT</pubDate>
    <dc:creator>HusamAbuOqer</dc:creator>
    <dc:date>2023-12-06T19:11:16Z</dc:date>
    <item>
      <title>Create and populate group layers with feature classes</title>
      <link>https://community.esri.com/t5/python-questions/create-and-populate-group-layers-with-feature/m-p/1357481#M69339</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a Python script that creates several group layers with specific names on a pre-created aprx file (GIS Pro) and then iterates through the folders and adds each feature class to its corresponding group layer.&lt;/P&gt;&lt;P&gt;I have several trials now and I am unable to create the group layers with specific names.&lt;/P&gt;&lt;P&gt;The main issue is that I am unable to add the feature classes even to a pre-created group layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 17:23:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-and-populate-group-layers-with-feature/m-p/1357481#M69339</guid>
      <dc:creator>HusamAbuOqer</dc:creator>
      <dc:date>2023-12-06T17:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Create and populate group layers with feature classes</title>
      <link>https://community.esri.com/t5/python-questions/create-and-populate-group-layers-with-feature/m-p/1357573#M69341</link>
      <description>&lt;P&gt;So, I was working on this the other day and it was a massive pain.&lt;/P&gt;&lt;P&gt;Below is a snippet from a larger script of mine. Given a file gdb, it'll add all the contents to a group layer named after said gdb.&lt;/P&gt;&lt;P&gt;This other thing too is that I had an impossible time trying to get "AddFeatureLayer" or whatever it is to work. Like I could create a layer but I couldn't move it because ??????? (Seriously Esri why is this so hard?). My solution here is to use addDataFromPath(), which will add a layer to your map. Then I feed it into my group layer, which for some reason duplicates it, so I just remove the layer that isn't in the group layer afterwards.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;mp = arcpy.mp.ArcProProject("CURRENT").activeMap

out_ds = #path\to\your\gdb
outName = #the basename of your gdb. This made sense in context.

outGroup = mp.createGroupLayer(os.path.basename(outName))
arcpy.env.workspace = out_ds

for fc in arcpy.ListFeatureClasses():
    fcLay = mp.addDataFromPath(os.path.join(out_ds,fc))
    mp.addLayerToGroup(outGroup, fcLay)
    mp.removeLayer(fcLay)
for tb in arcpy.ListTables():
    fcLay = mp.addDataFromPath(os.path.join(out_ds,tb))
    mp.addTableToGroup(outGroup, fcLay)
    mp.removeTable(fcLay)
for fd in arcpy.ListDatasets():
    fdGroup = mp.createGroupLayer(fd, outGroup)
    arcpy.env.workspace = os.path.join(out_ds, fd)
    for fc in arcpy.ListFeatureClasses():
        fcLay = mp.addDataFromPath(os.path.join(out_ds, fd, fc))
        mp.addLayerToGroup(fdGroup, fcLay, "TOP")
        mp.removeLayer(fcLay)
    arcpy.env.workspace = out_ds&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 18:53:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-and-populate-group-layers-with-feature/m-p/1357573#M69341</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-12-06T18:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: Create and populate group layers with feature classes</title>
      <link>https://community.esri.com/t5/python-questions/create-and-populate-group-layers-with-feature/m-p/1357589#M69342</link>
      <description>&lt;P&gt;It's a painful task to do!&lt;BR /&gt;Thank you so much, the first try worked to create a group layer and populate it.&lt;BR /&gt;I need to continue working on it as the code requires to create of multi-group layers and adding layers in different folders based on their names!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 19:11:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-and-populate-group-layers-with-feature/m-p/1357589#M69342</guid>
      <dc:creator>HusamAbuOqer</dc:creator>
      <dc:date>2023-12-06T19:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create and populate group layers with feature classes</title>
      <link>https://community.esri.com/t5/python-questions/create-and-populate-group-layers-with-feature/m-p/1357592#M69343</link>
      <description>&lt;P&gt;Yup! Check out the feature dataset section to see how to do that.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 19:12:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-and-populate-group-layers-with-feature/m-p/1357592#M69343</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-12-06T19:12:30Z</dc:date>
    </item>
  </channel>
</rss>

