I am trying to add a layer to my current map with this script using a script tool, however whenever I run the script tool it says addLayer failed.
What in my script can be fixed to get addLayer to work?
# import the library needed to add layer
import arcpy
arcpy.env.overwriteOutput = True
# access current project
aprx = arcpy.mp.ArcGISProject('CURRENT')
# access current map
m = aprx.activeMap
try:
# Create parameter for layer file you want to add
lf = arcpy.GetParameterAsText(0)
# Add layer to active map
m.addLayer(lf)
#Add message if layer added
arcpy.AddMessage("Layer added Successfully!")
except Exception as e:
arcpy.AddError(f"Error occured: {str(e)}")