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, do you have any suggestions about how 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")[0]
targetGroupLayer = aprxMap.listLayers('Group1')[0]
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