<?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 How to correctly populate an activeMap.addLayerToGroup() call? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-correctly-populate-an-activemap/m-p/1158562#M64180</link>
    <description>&lt;P&gt;UPDATED-- fixed the group layer reference at line 15; still doesn't work&lt;/P&gt;&lt;P&gt;I'm attempting to follow this answer:&amp;nbsp;&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/is-it-possible-to-create-a-new-group-layer-with/td-p/1068607" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-pro-questions/is-it-possible-to-create-a-new-group-layer-with/td-p/1068607&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But it is not working for me.&amp;nbsp; I have a script tool that performs various route solving problems using a defined OSRM instance.&amp;nbsp; The results return fine but tend to clutter up the table of contents.&amp;nbsp; My intent is to put the results of each run (lines, points) into its own group layer.&lt;/P&gt;&lt;P&gt;I can create the group layer without issue via an empty group layer .lyrx file that will be distributed with the release.&lt;/P&gt;&lt;P&gt;However, here's where I'm failing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# At this point I have feature classes in
# a list that I iterate over to add to the map

grplyrpath = os.path.join(Path(os.path.dirname(__file__)).parent, "res")
gprlyrfile = os.path.join(grplyrpath, "group.lyrx")
grplyr = arcpy.mp.LayerFile(grplyrfile)
osrm_group = active_map.addLayer(grplyr)[0]
osrm_group.name = f"OSRM {now}"  # now is the script start-time in string

for idx, rfc in enumerate(route_fc_list):
    osrm_lyr = active_map.addDataFromPath(rfc)
    if idx == 0:  # First route is primary/fastest route
        osrm_lyr.name = "OSRM Route (Primary)"
        # then do bunch of symbology
        active_map.addLayerToGroup(osrm_group, osrm_lyr)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this earns me an error in addLayerToGroup&lt;/P&gt;&lt;P&gt;ValueError: &amp;lt;MappingLayerFileObject object at (memory address)&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've also tried directly adding the feature classes to the group layer (which would be more efficient) but that failed too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone post a working example of how to prep a layer and add it into a group layer via arcpy?&lt;/P&gt;</description>
    <pubDate>Mon, 28 Mar 2022 20:33:04 GMT</pubDate>
    <dc:creator>EricEagle</dc:creator>
    <dc:date>2022-03-28T20:33:04Z</dc:date>
    <item>
      <title>How to correctly populate an activeMap.addLayerToGroup() call?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-correctly-populate-an-activemap/m-p/1158562#M64180</link>
      <description>&lt;P&gt;UPDATED-- fixed the group layer reference at line 15; still doesn't work&lt;/P&gt;&lt;P&gt;I'm attempting to follow this answer:&amp;nbsp;&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/is-it-possible-to-create-a-new-group-layer-with/td-p/1068607" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-pro-questions/is-it-possible-to-create-a-new-group-layer-with/td-p/1068607&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But it is not working for me.&amp;nbsp; I have a script tool that performs various route solving problems using a defined OSRM instance.&amp;nbsp; The results return fine but tend to clutter up the table of contents.&amp;nbsp; My intent is to put the results of each run (lines, points) into its own group layer.&lt;/P&gt;&lt;P&gt;I can create the group layer without issue via an empty group layer .lyrx file that will be distributed with the release.&lt;/P&gt;&lt;P&gt;However, here's where I'm failing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# At this point I have feature classes in
# a list that I iterate over to add to the map

grplyrpath = os.path.join(Path(os.path.dirname(__file__)).parent, "res")
gprlyrfile = os.path.join(grplyrpath, "group.lyrx")
grplyr = arcpy.mp.LayerFile(grplyrfile)
osrm_group = active_map.addLayer(grplyr)[0]
osrm_group.name = f"OSRM {now}"  # now is the script start-time in string

for idx, rfc in enumerate(route_fc_list):
    osrm_lyr = active_map.addDataFromPath(rfc)
    if idx == 0:  # First route is primary/fastest route
        osrm_lyr.name = "OSRM Route (Primary)"
        # then do bunch of symbology
        active_map.addLayerToGroup(osrm_group, osrm_lyr)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this earns me an error in addLayerToGroup&lt;/P&gt;&lt;P&gt;ValueError: &amp;lt;MappingLayerFileObject object at (memory address)&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've also tried directly adding the feature classes to the group layer (which would be more efficient) but that failed too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone post a working example of how to prep a layer and add it into a group layer via arcpy?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 20:33:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-correctly-populate-an-activemap/m-p/1158562#M64180</guid>
      <dc:creator>EricEagle</dc:creator>
      <dc:date>2022-03-28T20:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to correctly populate an activeMap.addLayerToGroup() call?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-correctly-populate-an-activemap/m-p/1158640#M64189</link>
      <description>&lt;P&gt;This works for me when I run it in the ArcGIS Pro python window&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject('CURRENT')
active_map = aprx.activeMap
rfc = r'E:\CW_Hub\temp\CW_Boundary_2009\CW_Boundary_2009.shp'

grplyrfile = r'E:\CW_Hub\temp\Group layer.lyrx'
grplyr = arcpy.mp.LayerFile(grplyrfile)
osrm_group = active_map.addLayer(grplyr)[0]
osrm_lyr = active_map.addDataFromPath(rfc)
active_map.addLayerToGroup(osrm_group, osrm_lyr)
active_map.removeLayer(osrm_lyr)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 28 Mar 2022 23:50:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-correctly-populate-an-activemap/m-p/1158640#M64189</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-03-28T23:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to correctly populate an activeMap.addLayerToGroup() call?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-correctly-populate-an-activemap/m-p/1158662#M64192</link>
      <description>&lt;P&gt;Thanks Don; maybe I am having trouble here but I don't see what I've done that is any different from what you've posted (except running it via script tool)... ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 02:01:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-correctly-populate-an-activemap/m-p/1158662#M64192</guid>
      <dc:creator>EricEagle</dc:creator>
      <dc:date>2022-03-29T02:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to correctly populate an activeMap.addLayerToGroup() call?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-correctly-populate-an-activemap/m-p/1159959#M64241</link>
      <description>&lt;P&gt;Right - it seems to be the equivalent.&amp;nbsp; Can you do something similar with your data and get it to work in the ArcGIS Pro python window? That might indicate a problem in your python environment.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 17:04:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-correctly-populate-an-activemap/m-p/1159959#M64241</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-03-31T17:04:13Z</dc:date>
    </item>
  </channel>
</rss>

