<?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 implement derived output parameter for ApplySymbologyFromLayer() in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/how-to-implement-derived-output-parameter-for/m-p/1362119#M6869</link>
    <description>&lt;P&gt;I'm trying to set feature symbology's from .lyrx files in a python script tool but am running into issues. The code runs with no errors but the .lyrx symbologies aren't applied (ie the symbologies don't change after script completion). I've opened a case with ESRI support, but it hasn't been much help. On the &lt;STRONG&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/apply-symbology-from-layer.htm" target="_self"&gt;tool documentation&lt;/A&gt;&lt;/STRONG&gt; page it says...&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;"&lt;BR /&gt;To see the symbology created in a script tool, the tool must include the layer as a &lt;A href="https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpro.arcgis.com%2Fen%2Fpro-app%2F3.2%2Farcpy%2Fgeoprocessing_and_python%2Fsetting-script-tool-parameters.htm%23GUID-8A3BFFDE-3923-4956-94D6-8960D3A68C7F&amp;amp;data=05%7C02%7Ccweir%40patrickco.com%7Cbad33572442440a7801808dbffef1939%7Cdcfbf1117f01472e8f20ab7b28448304%7C1%7C0%7C638385174662165160%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;amp;sdata=XnkBxNBdfAbIjCxVgFZoiKFsJDzC%2FWyqutmp3HMR1to%3D&amp;amp;reserved=0" target="_blank" rel="noopener"&gt;derived output parameter&lt;/A&gt;. Similarly, the &lt;SPAN&gt;Updated Input Layer&lt;/SPAN&gt; parameter value must be added as a derived model parameter &lt;A href="https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpro.arcgis.com%2Fen%2Fpro-app%2F3.2%2Fhelp%2Fanalysis%2Fgeoprocessing%2Fmodelbuilder%2Fmodelbuilder-vocabulary.htm&amp;amp;data=05%7C02%7Ccweir%40patrickco.com%7Cbad33572442440a7801808dbffef1939%7Cdcfbf1117f01472e8f20ab7b28448304%7C1%7C0%7C638385174662165160%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;amp;sdata=JFZXc3Ox2Fj8%2FZ0aZBeukRE%2FC67s6y4ucsKn0ARXgoE%3D&amp;amp;reserved=0" target="_blank" rel="noopener"&gt;model tool&lt;/A&gt; to see the symbology changes.”&lt;BR /&gt;"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;How can I successfully implement that into this code? I tried in Line 32 but had no luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def apply_lyrx(map_object, lyrx_folder):
    """
    Applys .lyrx files to layers in the TOC according to layer name

    Parameters:
    - map_object (arcpy.mp.ArcGISProject("").activeMap): Map object
    - lyrx_folder (path): path to .lyrx source folder

    Returns:
    None
    """
    # Loop through layers in the TOC
    for lyr in map_object.listLayers():
        if "primary" in lyr.name.lower():
            lyrx_file = "Primary.lyrx"
        elif "secondary" in lyr.name.lower():
            lyrx_file = "Secondary.lyrx"
        elif "pole" in lyr.name.lower() and "anno" not in lyr.name.lower():
            lyrx_file = "Pole.lyrx"
        elif "anno" in lyr.name.lower():
            lyrx_file = "Pole_Anno.lyrx"
        else:
            lyrx_file = "clip_poly.lyrx"

        symb_path = os.path.join(lyrx_folder, lyrx_file)

        # apply .lyrx file
        if lyr.isFeatureLayer:
            arcpy.ApplySymbologyFromLayer_management(lyr, symb_path)

            # Set layer as derived output parameter
            arcpy.SetParameterAsText(0, lyr)

            arcpy.AddMessage(f"'{lyrx_file}' applied to '{lyr}'")

        else:
            arcpy.AddMessage(f"'{lyr.name}' is not a feature layer...")

    arcpy.AddMessage("All .lyrx files applied...")

    aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PS: see attached .txt file for a stand-alone version of this code that works when run in the python window (symbologies get updated)... so I know it's something when running ApplySymbologyFromLayer() in a script tool.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Dec 2023 18:07:09 GMT</pubDate>
    <dc:creator>cweirpatrickco</dc:creator>
    <dc:date>2023-12-18T18:07:09Z</dc:date>
    <item>
      <title>How to implement derived output parameter for ApplySymbologyFromLayer()</title>
      <link>https://community.esri.com/t5/developers-questions/how-to-implement-derived-output-parameter-for/m-p/1362119#M6869</link>
      <description>&lt;P&gt;I'm trying to set feature symbology's from .lyrx files in a python script tool but am running into issues. The code runs with no errors but the .lyrx symbologies aren't applied (ie the symbologies don't change after script completion). I've opened a case with ESRI support, but it hasn't been much help. On the &lt;STRONG&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/apply-symbology-from-layer.htm" target="_self"&gt;tool documentation&lt;/A&gt;&lt;/STRONG&gt; page it says...&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;"&lt;BR /&gt;To see the symbology created in a script tool, the tool must include the layer as a &lt;A href="https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpro.arcgis.com%2Fen%2Fpro-app%2F3.2%2Farcpy%2Fgeoprocessing_and_python%2Fsetting-script-tool-parameters.htm%23GUID-8A3BFFDE-3923-4956-94D6-8960D3A68C7F&amp;amp;data=05%7C02%7Ccweir%40patrickco.com%7Cbad33572442440a7801808dbffef1939%7Cdcfbf1117f01472e8f20ab7b28448304%7C1%7C0%7C638385174662165160%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;amp;sdata=XnkBxNBdfAbIjCxVgFZoiKFsJDzC%2FWyqutmp3HMR1to%3D&amp;amp;reserved=0" target="_blank" rel="noopener"&gt;derived output parameter&lt;/A&gt;. Similarly, the &lt;SPAN&gt;Updated Input Layer&lt;/SPAN&gt; parameter value must be added as a derived model parameter &lt;A href="https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpro.arcgis.com%2Fen%2Fpro-app%2F3.2%2Fhelp%2Fanalysis%2Fgeoprocessing%2Fmodelbuilder%2Fmodelbuilder-vocabulary.htm&amp;amp;data=05%7C02%7Ccweir%40patrickco.com%7Cbad33572442440a7801808dbffef1939%7Cdcfbf1117f01472e8f20ab7b28448304%7C1%7C0%7C638385174662165160%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;amp;sdata=JFZXc3Ox2Fj8%2FZ0aZBeukRE%2FC67s6y4ucsKn0ARXgoE%3D&amp;amp;reserved=0" target="_blank" rel="noopener"&gt;model tool&lt;/A&gt; to see the symbology changes.”&lt;BR /&gt;"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;How can I successfully implement that into this code? I tried in Line 32 but had no luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def apply_lyrx(map_object, lyrx_folder):
    """
    Applys .lyrx files to layers in the TOC according to layer name

    Parameters:
    - map_object (arcpy.mp.ArcGISProject("").activeMap): Map object
    - lyrx_folder (path): path to .lyrx source folder

    Returns:
    None
    """
    # Loop through layers in the TOC
    for lyr in map_object.listLayers():
        if "primary" in lyr.name.lower():
            lyrx_file = "Primary.lyrx"
        elif "secondary" in lyr.name.lower():
            lyrx_file = "Secondary.lyrx"
        elif "pole" in lyr.name.lower() and "anno" not in lyr.name.lower():
            lyrx_file = "Pole.lyrx"
        elif "anno" in lyr.name.lower():
            lyrx_file = "Pole_Anno.lyrx"
        else:
            lyrx_file = "clip_poly.lyrx"

        symb_path = os.path.join(lyrx_folder, lyrx_file)

        # apply .lyrx file
        if lyr.isFeatureLayer:
            arcpy.ApplySymbologyFromLayer_management(lyr, symb_path)

            # Set layer as derived output parameter
            arcpy.SetParameterAsText(0, lyr)

            arcpy.AddMessage(f"'{lyrx_file}' applied to '{lyr}'")

        else:
            arcpy.AddMessage(f"'{lyr.name}' is not a feature layer...")

    arcpy.AddMessage("All .lyrx files applied...")

    aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PS: see attached .txt file for a stand-alone version of this code that works when run in the python window (symbologies get updated)... so I know it's something when running ApplySymbologyFromLayer() in a script tool.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 18:07:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-to-implement-derived-output-parameter-for/m-p/1362119#M6869</guid>
      <dc:creator>cweirpatrickco</dc:creator>
      <dc:date>2023-12-18T18:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to implement derived output parameter for ApplySymbologyFromLayer()</title>
      <link>https://community.esri.com/t5/developers-questions/how-to-implement-derived-output-parameter-for/m-p/1362206#M6870</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've run into this same problem before.&lt;/P&gt;&lt;P&gt;What worked for me was not using:&lt;/P&gt;&lt;P&gt;ApplySymbololgyFromLayer()&lt;/P&gt;&lt;P&gt;but instead using:&lt;/P&gt;&lt;P&gt;SetParameterSymbology()&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/setparametersymbology.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/setparametersymbology.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 19:40:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-to-implement-derived-output-parameter-for/m-p/1362206#M6870</guid>
      <dc:creator>cpehlke</dc:creator>
      <dc:date>2023-12-18T19:40:40Z</dc:date>
    </item>
  </channel>
</rss>

