# Import arcpy module import arcpy import os from arcpy.mp import * # Script arguments # tiflist = arcpy.GetParameterAsText(0) # Destination = arcpy.GetParameterAsText(1) # sdeconn = arcpy.GetParameterAsText(2) tiflist = "1624;1625;1626" Destination = r"D:\SymbTrans\SymbTrans\scripts\outputs" sdeconn = r"D:\SymbTrans\SymbTrans.sde" outfeature=tiflist DBName=arcpy.Describe(sdeconn).connectionProperties.database pathtable=sdeconn+"\\"+DBName+".sde."+"ForecastDataPath" Scratchenv = arcpy.env.scratchGDB arcpy.env.workspace = Scratchenv arcpy.env.overwriteOutput = True tiflist=tiflist.split(";") sql="" for row in tiflist: sql = sql+" objectid = "+str(row)+" OR " sql=sql[:-4] arcpy.AddMessage(sql) filesinput=[] scursor = arcpy.da.SearchCursor(pathtable,["path"],sql) for row in scursor: filesinput.append(row[0]) arcpy.AddMessage(filesinput) currentScriptPath=Destination+"\\"+"SymbologyOut"+"\\" templyrname="Template" arcpy.AddMessage(currentScriptPath) templyrs=LayerFile(os.path.join(currentScriptPath,templyrname+".lyrx")) tlyr=templyrs.listLayers(templyrname+".tif") arcpy.AddMessage(tlyr) tlyr=tlyr[0] symtemp = tlyr.symbology colorRamptemp= symtemp.colorizer.colorRamp arcpy.AddMessage("Template Symbology Read") for subdir, dirs, files in os.walk(currentScriptPath): for filename in files: if filename.lower().endswith(".tif"): filepath = os.path.join(currentScriptPath , filename) if filepath in filesinput: arcpy.AddMessage("Modifying Symbology of : ") filename=filename.replace(".tif","") arcpy.AddMessage(filename) gpout=arcpy.management.MakeRasterLayer(filepath,filename+".lyrx") newlyr=gpout.getOutput(0) sym = newlyr.symbology newlyr.symbology = symtemp newlyr.saveACopy(os.path.join(currentScriptPath,filename+".lyrx")) currrentlyr=LayerFile(os.path.join(currentScriptPath,filename+".lyrx")) clyr=currrentlyr.listLayers(filename+".lyrx") arcpy.AddMessage(clyr) clyr=clyr[0] sym = clyr.symbology sym.colorizer.colorRamp = colorRamptemp clyr.symbology = symtemp clyr.saveACopy(os.path.join(currentScriptPath,filename+".lyrx"))