<?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 Listing grouped layers in a Web Map in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/listing-grouped-layers-in-a-web-map/m-p/1377416#M9610</link>
    <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;I've worked out code below (to run in ArcGIS Pro Workbook) to list the layers in a Web Map.&amp;nbsp; This works fine for Classic Web Map, but if I'm using a New Web Map, with the layers services all added to Groups, then what is listed is just the Group names.&lt;/P&gt;&lt;P&gt;Can the code be modified to list the Group name, then the layers in each group?&lt;/P&gt;&lt;P&gt;Appreciate your support, please note I'm a bit of a novice so grateful for any detailed suggestions to modifying the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from arcgis.gis import GIS&lt;BR /&gt;from arcgis.mapping import WebMap&lt;BR /&gt;import arcpy&lt;/P&gt;&lt;P&gt;gis = GIS("pro")&lt;/P&gt;&lt;P&gt;# Search for web maps based on the query. Set max_items to -1 for all maps&lt;BR /&gt;webmaps_contents = gis.content.search("*",item_type="Web Map", max_items=500)&lt;/P&gt;&lt;P&gt;print('Number of Web Maps found: ' + str((len(webmaps_contents))))&lt;/P&gt;&lt;P&gt;n=0&lt;BR /&gt;#create web map objects from search results and print the web map title and layer name&lt;BR /&gt;for webmap_item in webmaps_contents:&lt;BR /&gt;if webmap_item.content_status != "deprecated": # Optional to include&lt;BR /&gt;&amp;nbsp; &amp;nbsp;n=n+1&lt;BR /&gt;&amp;nbsp; &amp;nbsp;print(n,webmap_item.title,webmap_item.content_status)&lt;BR /&gt;&amp;nbsp; &amp;nbsp;webmap_obj = WebMap(webmap_item)&lt;BR /&gt;&amp;nbsp; &amp;nbsp;l=0&lt;BR /&gt;&amp;nbsp; &amp;nbsp;for layer in webmap_obj.layers:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; l=l+1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; print('\t',l,layer.title)&lt;/P&gt;&lt;P&gt;print("Finished")&lt;/P&gt;</description>
    <pubDate>Fri, 02 Feb 2024 03:35:09 GMT</pubDate>
    <dc:creator>Kalu_Ribush</dc:creator>
    <dc:date>2024-02-02T03:35:09Z</dc:date>
    <item>
      <title>Listing grouped layers in a Web Map</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/listing-grouped-layers-in-a-web-map/m-p/1377416#M9610</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;I've worked out code below (to run in ArcGIS Pro Workbook) to list the layers in a Web Map.&amp;nbsp; This works fine for Classic Web Map, but if I'm using a New Web Map, with the layers services all added to Groups, then what is listed is just the Group names.&lt;/P&gt;&lt;P&gt;Can the code be modified to list the Group name, then the layers in each group?&lt;/P&gt;&lt;P&gt;Appreciate your support, please note I'm a bit of a novice so grateful for any detailed suggestions to modifying the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from arcgis.gis import GIS&lt;BR /&gt;from arcgis.mapping import WebMap&lt;BR /&gt;import arcpy&lt;/P&gt;&lt;P&gt;gis = GIS("pro")&lt;/P&gt;&lt;P&gt;# Search for web maps based on the query. Set max_items to -1 for all maps&lt;BR /&gt;webmaps_contents = gis.content.search("*",item_type="Web Map", max_items=500)&lt;/P&gt;&lt;P&gt;print('Number of Web Maps found: ' + str((len(webmaps_contents))))&lt;/P&gt;&lt;P&gt;n=0&lt;BR /&gt;#create web map objects from search results and print the web map title and layer name&lt;BR /&gt;for webmap_item in webmaps_contents:&lt;BR /&gt;if webmap_item.content_status != "deprecated": # Optional to include&lt;BR /&gt;&amp;nbsp; &amp;nbsp;n=n+1&lt;BR /&gt;&amp;nbsp; &amp;nbsp;print(n,webmap_item.title,webmap_item.content_status)&lt;BR /&gt;&amp;nbsp; &amp;nbsp;webmap_obj = WebMap(webmap_item)&lt;BR /&gt;&amp;nbsp; &amp;nbsp;l=0&lt;BR /&gt;&amp;nbsp; &amp;nbsp;for layer in webmap_obj.layers:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; l=l+1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; print('\t',l,layer.title)&lt;/P&gt;&lt;P&gt;print("Finished")&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 03:35:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/listing-grouped-layers-in-a-web-map/m-p/1377416#M9610</guid>
      <dc:creator>Kalu_Ribush</dc:creator>
      <dc:date>2024-02-02T03:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Listing grouped layers in a Web Map</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/listing-grouped-layers-in-a-web-map/m-p/1377572#M9613</link>
      <description>&lt;P&gt;Hi, this small update should work well for your needs:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;l = 0
for layer in webmap_obj.layers:
    l += 1
    print(l, layer.title)
    if hasattr(layer, "layers"):
        for sublayer in layer.layers:
            print("\t", sublayer.title)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 14:58:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/listing-grouped-layers-in-a-web-map/m-p/1377572#M9613</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2024-02-02T14:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Listing grouped layers in a Web Map</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/listing-grouped-layers-in-a-web-map/m-p/1378033#M9625</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/86309"&gt;@EarlMedina&lt;/a&gt;&amp;nbsp;,&amp;nbsp; that worked.&lt;/P&gt;&lt;P&gt;Really appreciate the help.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 05:37:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/listing-grouped-layers-in-a-web-map/m-p/1378033#M9625</guid>
      <dc:creator>Kalu_Ribush</dc:creator>
      <dc:date>2024-02-05T05:37:53Z</dc:date>
    </item>
  </channel>
</rss>

