ModelBuilder in ArcGIS Pro – Iterating Over Features in Group Layer with Wildcard Identifier

arcgis-proerror-000840group-layeriteratormodelbuilder

enter image description here

In the ModelBuilder of ArcGIS Pro 2.8.1, using Iterate Layers, I want to iterate over features that are in a group layer. It seems like I should be able to identify this group layer by using a Wildcard, which the user will provide as a parameter. I am then passing these layers as the input to the rest of the model. The issue is when I choose Layer Type as Group Layer (within the Iterate Layer options), I later get the error 000840 (The value is not a Feature Layer), when I try to pass the Output Layer to the next tool, which is Feature Class to Feature Class. It does not accept Group Layers as an input.

My goal is to iterate through all layers(which are feature services) in a group layer, export them to a gbd, then export them as shapefile to a folder. The purpose is creating backups of field data that can then be edited in ArcGIS Pro project. I am going with this Group Layer Approach since the ArcGIS Pro project template has a group layer "Field Data". Field staff will drag in the appropriate layers that need backed up by this Model.

The model as pictured runs when Iterate Features is set to Feature Layers, but not Group Layers.

So how do I just iterate through all the layers within the desired Group Layer?

Best Answer

This can be solved in modelbuilder with a tiny bit of python as hinted by @keggering.

The model is this:

Model

  1. The iterator is simply iterating over ALL FeatureLayers with no wildcards

  2. The string variable GroupLayer name contains the name of the group layer in the map, in your case "Field data", note it is a precondition to the calculate value tool whose output is a precondition to the copy feature tool. Also note the output Name from the iterator is also a precondition to the calculate value tool.

  3. Calculate value tool is set up as:

Calculate Value tool

The code block is:

import arcpy
def inGroup(grplyr,layername):
  aprx = arcpy.mp.ArcGISProject("CURRENT")
  map = aprx.listMaps()[0]
  layer = map.listLayers(layername)[0]
  longName = layer.longName
  if grplyr in longName:
    return True
  else:
    return False

The code is simply asking if the full path name in the project includes the group layer name, if it does set output to TRUE else FALSE. The code is assuming you have only 1 map in the project file, if you have more it is taking the top one only.

Related Question