Help with sync.NewLayer

89
1
10-16-2020 08:25 AM
JohnMossing
New Contributor II

ArcPro 2.3.3. Automated project building using arcpy in a .pyt script. The legend.syncNewLayer = True line is not syncronizing or adding the layers into the legend element. The code is not producing any errors, seems to run, just nothing is getting added to the legend element. Not sure if I am doing something wrong of if there is some bug or other issue. I reviewed the LegendElement—ArcGIS Pro | Documentation my syntax seems to look correct:

lyt = aprx.listLayouts("Layout Name")[0]

m = aprx.listMaps("Analysis_Map")[0]

legend = lyt.listElements("LEGEND_ELEMENT", "Legend")[0]

legend.syncNewLayer = True

....

....

Then I iterate over all the layers and create them and add them to the TOC. I have also tried to place this line of code inline with creating the layers and nothing happens with the legend.

Any advise would be appreciated.

0 Kudos
1 Reply
BobCapezza
New Contributor

I am having the same issue in ArcGIS Pro 2.5.2 but in reverse, every time I add the layer in the TOC, they all show up in the legend.  There are some layers that I do not want in the legend (ortho imagery, hillshade, etc.).  When I use legend.syncNewLayer = False before adding those layers, they still show up in the legend after adding them to the TOC.  However, when I use this command in the Python Window, it DOES work, just not when running the python script.  Either I am missing a step and/or there is some sort of disconnect that I am not aware of.  If anyone can test it out that would be great.  Thank you.

0 Kudos