Select to view content in your preferred language

layer transparency not updating

608
3
01-05-2023 11:52 AM
BarakGarty
Occasional Contributor

Got few layer (3) in a map in ArcGIS Pro project. Before I export the layout that its MapFrame is reference to the map holding these 3 layers I am trying to set the top 2 layers transparency so the bottom layer will be visible later when the layout is exported (as PDF file that is). I also tried to change the bottom layer to color black.

 

The changes does not takes place. I don't see that the layers I call a change in transparency (lyr1 & lyr2; see code below) actually become less opaque. If I look at the color properties if each of these layers the transparency  value is 0 and not the 70 or 60 I set it to. lyr3 is not turning black.

I am adding the code here, if anyone can suggest what am I doing wrong and how I can fix it, I'll appreciate it.

import arcpy
import arcpy.mp as map
from arcpy import env as ENV

try:
	#init variables:
	ENV.workspace = r"C:\Users\User\Desktop\PythonClassHWEx\L10_ClassWork\Ex10\Ex10.gdb"
	ENV.overwriteOutput = True
	arcpy.env.addOutputsToMap = False
	aprx = map.ArcGISProject(r"C:\Users\User\Desktop\PythonClassHWEx\L10_ClassWork\Ex10\Ex10_updated.aprx")
	map2 = aprx.listMaps('Map2')[0]
	lyr1 = map2.listLayers('layer1')[0]
	lyr2 = map2.listLayers('layer2')[0]
	lyr3 = map2.listLayers('layer3')[0]

	#Set layer 1&2 transparency:
	lyr1.transperancy = 70
	lyr2.transperancy = 60
	lyr3.symbology.renderer.symbol.color = {'RGB' : [255, 0, 0, 0]}

	#Export layout2 to PDF
    output = r"C:\Users\User\Desktop\PythonClassHWEx\L10_ClassWork\Ex10\Layout2.pdf"
    pdflyt = aprx.listLayouts("Layout2*")[0]
    pdflyt.exportToPDF(output)     
    print("Finished exporting layout2 as PDF file\n")
	
	
	print('Script Done!')
    
except arcpy.ExecuteError:
    print(arcpy.ExecuteError.args[0])

except Exception as e:
    print("Error: " + e.args[0])

 

0 Kudos
3 Replies
SvenHarpering55
Emerging Contributor

Maybe you have to save the project first before exporting the layout: aprx.save().

0 Kudos
BarakGarty
Occasional Contributor

Hi Sven,

My issue with that command layer.transperancy = someIntValue, is that even when I just type it from the console (after referencing one of the project's map layers as that layer I am trying to change) that nothing happens on screen. When I check after run that one line of code, to the layer color properties, the transparency value, originally 0 (not transparent) is still 0; its like there no effect at all.

 

Is there even a possibility to change the layers colors or transparencies with python code via arcpy?

0 Kudos
SvenHarpering55
Emerging Contributor

I know the problem when I address a project by path in the script or directly in ArcGIS Pro. Then I always had to save the project so that changes would also be visible in the layout.

What happens if you use the value "CURRENT" instead of the path? The change should then be directly visible. Also for the transparency.

0 Kudos