AnsweredAssumed Answered

SaveToLayerFile_management function and symbology

Question asked by ALAIN.MARTINEAU@AECOM.COM on Sep 19, 2018
Latest reply on Sep 25, 2018 by Dan_Patterson

Hi all. I'm in trouble with the SaveToLayerFile_management function in a python script for arcgis pro 2.1.2. The script is setting a symbology that works but happens to not beeing saved on disk. I mean the lyrx file is done but doesn't contain the symbology. I've tried many changes in vain. The code below works properly on the python console however. For info, I changed here somes values initially gotten with GetParameterAsText.



Mxd ="Current")
MapPath = Mxd.filePath
ActMap = Mxd.activeMap
LyrName = 'Benzene'
SeuilsNb = 2
Seuils = "10;580" #string vers list
fileName = os.path.basename(MapPath)
fileNameLen = len(fileName)+1
Ws = MapPath[0:-fileNameLen]
in_layer = ActMap.listLayers(LyrName)[0]
LayerSource = in_layer.dataSource
TargetFolder = "J:\\00-Template-job_Oct2017\\900_CAD_GIS\\Lyr"
Labels = []

for Seuil in Seuils:
if Seuil == Seuils[0]:
Labels.append("Inférieur à " + Seuil)
BorneInf = Seuil
Labels.append(BorneInf + " à " + Seuil)
BorneInf = Seuil

Symbologie = in_layer.symbology
Symbologie.renderer.classificationField = 'result_value_atof'
Symbologie.renderer.breakCount = SeuilsNb
i = 0
for bc in Symbologie.renderer.classBreaks:
bc.upperBound = float(Seuils[i])
bc.label = Labels[i]
i =+1
in_layer.symbology = Symbologie

arcpy.SaveToLayerFile_management(LyrName,os.path.join(TargetFolder, LyrName + ".lyrx"))

Thanks in advance for the help!