I am currently trying to add all the feature classes contained within a gdb to a group layer in ArcGIS Pro via a script. I have however not managed to add more than one single feature class at a time.
By looking at the script below, does any of you have any suggestions to solve this?
arcpy.env.workspace = "C:\\TEST_ENV\\AGOL_output\\AGOL.gdb" datasets = arcpy.ListDatasets(feature_type='feature') datasets = [''] + datasets if datasets is not None else  rootPath_aprx = 'C:\\TEST_ENV\\AGOL_output\\' aprx = arcpy.mp.ArcGISProject(rootPath_aprx + 'WMStest1.aprx') aprxMap = aprx.listMaps("Map") targetGroupLayer = aprxMap.listLayers('Group1') for ds in datasets: for fc in arcpy.ListFeatureClasses(feature_dataset=ds): path = os.path.join(arcpy.env.workspace, ds, fc) print(path) for GroupLayer in targetGroupLayer: # print(l) if str(GroupLayer) == GroupName: try: aprxMap.addLayerToGroup(aprxMap, targetGroupLayer, path, ['AUTO_ARRANGE']) except: print("gah.") aprx.save()
The error I am receiving when I run the script is:
for GroupLayer in targetGroupLayer: TypeError: 'Layer' object is not iterable