I have some scripting where the goal has been to create data and spatializes them from tables through an FME workbench saved as a data interop tool and saved in a FGDB, which then a script is ran to add them into the map frame, and changes the names of the feature classes. Those all work, however when I get to the symbology script I have, it runs and works just fine in the window, but does not work in a model.
import arcpy
# Set the map name where you want to symbolize the feature class
map_name = "Map" # Change this to match your map name
# Get the current project
aprx = arcpy.mp.ArcGISProject("CURRENT")
# Get the map frame
map_frame = aprx.listMaps(map_name)[0]
# Dictionary to map layer name to symbology layer file (for one layer)
layer_to_symbology_mapping = {
"Layer_Example": r"D:\Layer_Example.lyrx"
}
# Loop through the layers in the map frame and apply symbology
for lyr in map_frame.listLayers():
# Check if the layer name has a mapping in the dictionary
if lyr.name in layer_to_symbology_mapping:
symbology_layer = layer_to_symbology_mapping[lyr.name]
# Apply symbology from the layer file
arcpy.management.ApplySymbologyFromLayer(lyr, symbology_layer)
print(f"Symbology applied to {lyr.name} using {symbology_layer}")
# Save the project
aprx.save()
I am a bit stumped, when it runs in ModelBuilder, it doesn't throw an error, it will give a lock on the layer in the drawing order, but nothing happens, but works like a charm in the Python window. Any ideas on what could be happening?