Hi!
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.
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”.
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.
The .stylx file works in “Match Layer Symbology To A Style”, so there is no problem.
Can someone please help me? 🙂
import arcpy
# Definiera funktionen för att matcha lagersymboliken mot en stil med hjälp av ett fält
def match_layer_symbology_to_style(input_layers):
try:
style_file = r"M:\GIS\ArcGIS...."
match_field = "antikv_bed"
for layer in input_layers:
arcpy.management.MatchLayerSymbologyToAStyle(layer, style_file, True)
arcpy.AddMessage(f"Symbology successfully matched to style for layer: {layer}")
except arcpy.ExecuteError:
arcpy.AddError(arcpy.GetMessages(2))
except Exception as e:
arcpy.AddError(str(e))
# Parametrar för scriptverktyget
input_layers = arcpy.Parameter(
displayName="Input Layers",
name="input_layers",
datatype="GPValueTable",
parameterType="Required",
direction="Input")
# Definiera parametrarna för scriptverktyget
params = [input_layers]
# Kör funktionen med de angivna parametrarna
def main():
input_layers = arcpy.GetParameter(0) # Hämta parametern som en lista av lager
match_layer_symbology_to_style(input_layers)
if __name__ == "__main__":
main()