<?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 addLayerToGroup Mapping Class  help in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/addlayertogroup-mapping-class-help/m-p/1242817#M63649</link>
    <description>&lt;P&gt;Hi.&amp;nbsp; I am trying to add 30+ layers from same feature class to the Table of Contents (TOC) into groups, each with it's own definition query. My attribute table has this basic design (note that I simplified it and reduced size):&lt;/P&gt;&lt;TABLE border="0" width="384" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="64" height="20"&gt;site&lt;/TD&gt;&lt;TD width="64"&gt;spp1&lt;/TD&gt;&lt;TD width="64"&gt;spp2&lt;/TD&gt;&lt;TD width="64"&gt;spp3&lt;/TD&gt;&lt;TD width="64"&gt;spp4&lt;/TD&gt;&lt;TD width="64"&gt;spp5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;site1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;site2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;site3&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;site4&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;site5&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each&amp;nbsp;&lt;STRONG&gt;Site&lt;/STRONG&gt; includes an attribute for each species (&lt;STRONG&gt;spp1,spp2,&lt;/STRONG&gt;etc.) with the value = count - i.e. at Site 1 there were 3 spp2.&lt;/P&gt;&lt;P&gt;I ultimately want one layer group per site in my TOC.&amp;nbsp; Each layer group receives a layer per species.&amp;nbsp; In this example, each site will get 5 layers - one for each spp.&lt;/P&gt;&lt;P&gt;I am able to create the Groups&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# 1) CREATE GROUPS
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('site_map')[0]

# Add each group to Table of Contents
# Each group will get multiple layers
sites = ['site1','site2','site3','site4']
group_layers = []
for s in sites:
    group_layers.append(m.createGroupLayer(s))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I am able to then add layers to each group BUT I cannot add a defQuery per layer.&amp;nbsp; I don't know how to access the defQuery Property from the groupLayer attribute in this loop via (line 9).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;lyrx = r'path/to/data.lyrx'
lyr_file = arcpy.mp.LayerFile(lyrx)
sites = ['site1','site2','site3','site4','site5']
target_cols = ['spp1','spp2','spp3','spp4','spp5']
for s in sites:
    gl = [gl for gl in group_layers if gl.name == s]
    gl = gl[0]
    for tc in target_cols:
        lyr = m.addLayerToGroup(gl, lyr_file)
        def_q = r'site=="{}"'.format(s)
        lyr.definitionQuery(def_q)      &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Is there a way to set a definitionQuery via the defintionQuery property on each layer, preferably within this for loop? Note that I receive this error for line 11:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;AttributeError&lt;/SPAN&gt;: The attribute 'definitionQuery' is not supported on this instance of Layer.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Note that this obviously works&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;m.listLayers()[0].definitionQuery='def query whatever'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;but I would love to do it within the for loop via the groupLayer property.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Dec 2022 21:34:29 GMT</pubDate>
    <dc:creator>ZacharyUhlmann1</dc:creator>
    <dc:date>2022-12-20T21:34:29Z</dc:date>
    <item>
      <title>addLayerToGroup Mapping Class  help</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/addlayertogroup-mapping-class-help/m-p/1242817#M63649</link>
      <description>&lt;P&gt;Hi.&amp;nbsp; I am trying to add 30+ layers from same feature class to the Table of Contents (TOC) into groups, each with it's own definition query. My attribute table has this basic design (note that I simplified it and reduced size):&lt;/P&gt;&lt;TABLE border="0" width="384" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="64" height="20"&gt;site&lt;/TD&gt;&lt;TD width="64"&gt;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&gt; includes an attribute for each species (&lt;STRONG&gt;spp1,spp2,&lt;/STRONG&gt;etc.) with the value = count - i.e. at Site 1 there were 3 spp2.&lt;/P&gt;&lt;P&gt;I ultimately want one layer group per site in my TOC.&amp;nbsp; Each layer group receives a layer per species.&amp;nbsp; In this example, each site will get 5 layers - one for each spp.&lt;/P&gt;&lt;P&gt;I am able to create the Groups&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# 1) CREATE GROUPS
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('site_map')[0]

# Add each group to Table of Contents
# Each group will get multiple layers
sites = ['site1','site2','site3','site4']
group_layers = []
for s in sites:
    group_layers.append(m.createGroupLayer(s))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I am able to then add layers to each group BUT I cannot add a defQuery per layer.&amp;nbsp; I don't know how to access the defQuery Property from the groupLayer attribute in this loop via (line 9).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;lyrx = r'path/to/data.lyrx'
lyr_file = arcpy.mp.LayerFile(lyrx)
sites = ['site1','site2','site3','site4','site5']
target_cols = ['spp1','spp2','spp3','spp4','spp5']
for s in sites:
    gl = [gl for gl in group_layers if gl.name == s]
    gl = gl[0]
    for tc in target_cols:
        lyr = m.addLayerToGroup(gl, lyr_file)
        def_q = r'site=="{}"'.format(s)
        lyr.definitionQuery(def_q)      &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Is there a way to set a definitionQuery via the defintionQuery property on each layer, preferably within this for loop? Note that I receive this error for line 11:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;AttributeError&lt;/SPAN&gt;: The attribute 'definitionQuery' is not supported on this instance of Layer.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Note that this obviously works&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;m.listLayers()[0].definitionQuery='def query whatever'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;but I would love to do it within the for loop via the groupLayer property.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2022 21:34:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/addlayertogroup-mapping-class-help/m-p/1242817#M63649</guid>
      <dc:creator>ZacharyUhlmann1</dc:creator>
      <dc:date>2022-12-20T21:34:29Z</dc:date>
    </item>
  </channel>
</rss>

