<?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 Trouble with script regarding matching symbology to a .stylx in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/trouble-with-script-regarding-matching-symbology/m-p/1386734#M69958</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I am new to python, but figured I could script a tool for me and my collegues to use to automate some of our work.&lt;/P&gt;&lt;P&gt;The first tool I am trying to create will allow the user to choose multiple layers and match them to a specific .stylex-file and the value will be set to antikv_bed. So it is an upgraded, but simpler version of the tool “Match Layer Symbology To A Style”.&lt;/P&gt;&lt;P&gt;After a couple of tries, I gave up and consulted ChatGPT, and it came up with the following code. It runs, without errors, but didn’t change any of the symbols.&lt;/P&gt;&lt;P&gt;The .stylx file works in “Match Layer Symbology To A Style”, so there is no problem.&lt;/P&gt;&lt;P&gt;Can someone please help me? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;# Definiera funktionen för att matcha lagersymboliken mot en stil med hjälp av ett fält&lt;BR /&gt;def match_layer_symbology_to_style(input_layers):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; try:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; style_file = r"M:\GIS\ArcGIS...."&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; match_field = "antikv_bed"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for layer in input_layers:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.management.MatchLayerSymbologyToAStyle(layer, style_file, True)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.AddMessage(f"Symbology successfully matched to style for layer: {layer}")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; except arcpy.ExecuteError:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.AddError(arcpy.GetMessages(2))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; except Exception as e:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.AddError(str(e))&lt;/P&gt;&lt;P&gt;# Parametrar för scriptverktyget&lt;BR /&gt;input_layers = arcpy.Parameter(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; displayName="Input Layers",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; name="input_layers",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; datatype="GPValueTable",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; parameterType="Required",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; direction="Input")&lt;/P&gt;&lt;P&gt;# Definiera parametrarna för scriptverktyget&lt;BR /&gt;params = [input_layers]&lt;/P&gt;&lt;P&gt;# Kör funktionen med de angivna parametrarna&lt;BR /&gt;def main():&lt;BR /&gt;&amp;nbsp; &amp;nbsp; input_layers = arcpy.GetParameter(0) # Hämta parametern som en lista av lager&lt;BR /&gt;&amp;nbsp; &amp;nbsp; match_layer_symbology_to_style(input_layers)&lt;/P&gt;&lt;P&gt;if __name__ == "__main__":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; main()&lt;/P&gt;</description>
    <pubDate>Mon, 26 Feb 2024 14:41:50 GMT</pubDate>
    <dc:creator>Annie_Rosen</dc:creator>
    <dc:date>2024-02-26T14:41:50Z</dc:date>
    <item>
      <title>Trouble with script regarding matching symbology to a .stylx</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-script-regarding-matching-symbology/m-p/1386734#M69958</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I am new to python, but figured I could script a tool for me and my collegues to use to automate some of our work.&lt;/P&gt;&lt;P&gt;The first tool I am trying to create will allow the user to choose multiple layers and match them to a specific .stylex-file and the value will be set to antikv_bed. So it is an upgraded, but simpler version of the tool “Match Layer Symbology To A Style”.&lt;/P&gt;&lt;P&gt;After a couple of tries, I gave up and consulted ChatGPT, and it came up with the following code. It runs, without errors, but didn’t change any of the symbols.&lt;/P&gt;&lt;P&gt;The .stylx file works in “Match Layer Symbology To A Style”, so there is no problem.&lt;/P&gt;&lt;P&gt;Can someone please help me? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;# Definiera funktionen för att matcha lagersymboliken mot en stil med hjälp av ett fält&lt;BR /&gt;def match_layer_symbology_to_style(input_layers):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; try:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; style_file = r"M:\GIS\ArcGIS...."&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; match_field = "antikv_bed"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for layer in input_layers:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.management.MatchLayerSymbologyToAStyle(layer, style_file, True)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.AddMessage(f"Symbology successfully matched to style for layer: {layer}")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; except arcpy.ExecuteError:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.AddError(arcpy.GetMessages(2))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; except Exception as e:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.AddError(str(e))&lt;/P&gt;&lt;P&gt;# Parametrar för scriptverktyget&lt;BR /&gt;input_layers = arcpy.Parameter(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; displayName="Input Layers",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; name="input_layers",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; datatype="GPValueTable",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; parameterType="Required",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; direction="Input")&lt;/P&gt;&lt;P&gt;# Definiera parametrarna för scriptverktyget&lt;BR /&gt;params = [input_layers]&lt;/P&gt;&lt;P&gt;# Kör funktionen med de angivna parametrarna&lt;BR /&gt;def main():&lt;BR /&gt;&amp;nbsp; &amp;nbsp; input_layers = arcpy.GetParameter(0) # Hämta parametern som en lista av lager&lt;BR /&gt;&amp;nbsp; &amp;nbsp; match_layer_symbology_to_style(input_layers)&lt;/P&gt;&lt;P&gt;if __name__ == "__main__":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; main()&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2024 14:41:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-script-regarding-matching-symbology/m-p/1386734#M69958</guid>
      <dc:creator>Annie_Rosen</dc:creator>
      <dc:date>2024-02-26T14:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with script regarding matching symbology to a .stylx</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-script-regarding-matching-symbology/m-p/1387283#M69966</link>
      <description>&lt;P&gt;I am guessing, the reason it does not work because you use the arcpy.GetParameter. You could probably use arcpy.GetParameterAsText if your value is string. I never use arcpy.GetParameter so probably you need to "parse" or get the value inside GetParameter first because your input is GPValueTable.&lt;/P&gt;&lt;P&gt;Another alternative, you might create csv file and put as an input. Then, tried to parsing the value in the csv as the input of your&amp;nbsp;&lt;STRONG&gt;match_layer_symbology_to_style&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Hope it helps you.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 09:59:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-script-regarding-matching-symbology/m-p/1387283#M69966</guid>
      <dc:creator>AlexanderDanielPratama</dc:creator>
      <dc:date>2024-02-27T09:59:34Z</dc:date>
    </item>
  </channel>
</rss>

