layer list updates with changes in TOC using arcpy

2180
5
01-07-2021 08:49 AM
Status: Closed
Ann123
by
New Contributor III

when using the python interpreter window within ArcGIS Desktop, the layer list does not update if the table of contents changes.  For example, in my .mxd I have three layers - but when I'm writing a command, for example arcpy.MakeFeaureLayer_management, the auto-populated layer list does not reflect the layers that are currently in the table of contents.  See image for example.  Is this a bug or what?  If it's a bug, it should be fixed.  

5 Comments
JoshuaBixby

Looking at the screenshot, I see two of the layers listed, and I suspect the third is listed if you scroll down.  The real issue is that the list is cluttered up with old layers that are no longer in the TOC.  Have you run any script tools?  This can happen when script tools create layers and don't clean them up correctly.

KoryKramer

I see the same behavior in ArcMap 10.8.1

KoryKramer_0-1610057172411.png

I haven't been able to figure out a way to clear/flush the Python window's cache (if that is the correct term).

For what it's worth, when I try this in ArcGIS Pro, adding layers to a map is picked up in the Python window right away:

KoryKramer_1-1610057342700.png

If I then remove a bunch of those layers, the Python window will still show them in the layer list (like ArcMap) BUT I can refresh the map and then the Python window's layer list reflects the current layers in the Contents pane.

KoryKramer_2-1610057451105.png

So it may be a bug in ArcMap, but it looks like refreshing the map works in ArcGIS Pro.

Ann123
by

@JoshuaBixby - yes, that is exactly the problem.  The layer list is not refreshed in the python window as content is removed from the TOC layer list.    And yes @KoryKramer I have tried refreshing ArcMap as well as resaving and save as after removing layers - but the window clutter is still there.  The good part is that the *new* layers do show up - so this is more an annoyance, an unexpected and unanticipated behavior.  There needs to be a way to flush the window or clear the python cache, as you say, in ArcGIS Desktop.  

Glad to hear that it appears to be corrected in Pro.  

DuncanHornby

Interesting problem, exists in 10.6 too but I have found away to refresh that list. It's not perfect but it worked for me.

Remove the layer from the TOC, then in the python command line window you need to type:

arcpy.Exists("xxx") where xxx was the layer name. It will return FALSE as expected but it will also update the list and remove the missing layer.

 

KoryKramer
Status changed to: Closed

In reviewing ideas for consideration we came across this one again. There will be no changes made to ArcMap and since refresh is working in ArcGIS Pro, we're closing the idea.

Thank you.