I have a script that needs to:
- Load a specific .lyrx file into multiple maps
- Update each loaded layer's source to point to an input parameter
- Maintain the symbology from the .lyrx file
Current attempts result in broken layers. Here's my current approach:
def _ensure_site_layer(map_obj, site_fc_path, layer_name=SITE_LAYER_NAME):
"""Add site boundary layer to map"""
try:
# Remove any existing site boundary layers
for lyr in list(map_obj.listLayers()):
if lyr.name in (layer_name, "SiteBoundary_Export", "HE_SiteBoundary"):
map_obj.removeLayer(lyr)
# Trying to add layer file and update its source
SPECIFIC_LF = r"lyrx source removed"
lf = arcpy.mp.LayerFile(SPECIFIC_LF)
map_obj.addLayer(lf, "TOP")
# Need help with this part - updating the source
# site_fc_path contains the input parameter path
return added_layer
except Exception as e:
arcpy.AddWarning(f"_ensure_site_layer failed: {str(e)}")
return None
How the Function is Called:
# Example of how this function is used in the script
prof_map = _add_layers_to_profile_map(site_fc_path, tran_fc_path)
he_map = _he_add_layers_to_map(site_fc_path, he_buffer_fc_path, he_layer_paths)
# etc...
Does anyone know how i can get this script to load the lyrx correctly and change its source?