I have a blank map. And I have a shapefile. I would like to add the shapefile to the map document, change its colour (which I figured out using @AlexTereshenkov's answer to Adding a layer with specific color to map in ArcPy) and set its transparency.
My plan is to make a layer from the shapefile (
MakeFeatureLayer_management), add the resulting layer to the map document (
mapping.AddLayer) and then change the transparency using
As it was explained to me in the other question, I need to reference the map layer not the feature layer. I assume the same applies for setting the layer's transparency. I tried both:
import arcpy, os ### Set directory arcpy.env.workspace = ... arcpy.env.overwriteOutput = 1 ### Define inputs yellow = "symbology/yellow.lyr" city = boston year = 2000 # Set map document mxd_city_year = arcpy.mapping.MapDocument(r"...\blank_map.mxd") DF = arcpy.mapping.ListDataFrames(mxd_city_year) # Add layers arcpy.MakeFeatureLayer_management("states/continental_US.shp", "us") basis = arcpy.mapping.Layer("us") arcpy.mapping.AddLayer(DF, basis, "AUTO_ARRANGE") map_lyr = arcpy.mapping.ListLayers(mxd_city_year, wildcard="us", data_frame=DF) arcpy.ApplySymbologyFromLayer_management(map_lyr, yellow) # Set transparency (the part that does not work!) map_lyr.transparency = 0 basis.transparency = 0 # Save map mxd_city_year.saveACopy("thresh_" + city + "_" + year + ".mxd")
However, neither referencing the feature layer (
basis.transparency = 0) nor the map layer (
map_lyr.transparency = 0) seems to work. Does anyone know why?