I created a code that gets multiple layers from the parameters and makes them visible.
import arcpy
selectLayerLists=arcpy.GetParameterAsText(0) #LayerList
aprx=arcpy.mp.ArcGISProject("CURRENT")
lay=aprx.activeView #Layout
mf=lay.listElements("mapframe_element","*")[0]
map=mf.map
Lyr_list=selectLayerLists.split(";")
arcpy.AddMessage(Lyr_list)
for lyr in Lyr_list:
map.listLayers(lyr)[0].visible=True
Layer structure:
ryoho
ryoho/L02
ryoho/L01
L02
L01
The layer selected as the parameter:
ryoho
L02
L01
Code execution results:
As shown in the image, the group layer and layers with the same name within the group have been switched to display.
How can you get the results you want with the parameters?
As an experiment, I retrieved the parameters with "GetParameter" and set the retrieved layer.visible=True, but the layer did not appear.
In 3.2.2, layers with the same name were distinguished as "Layer1:1" and "Layer1:2", so this code worked without any problems, but after updating to 3.3.1, the following situation occurred.
Due to the nature of my work, there are many layers with the same name, and changing the layer names for the sake of creating legends is not a good idea.
I would appreciate any ideas on how to solve this problem.
I would also like to know if this problem is only occurring in my environment.