How to moveLayers in ArcPro in a Python Toolbox - command not working as documented

321
6
Jump to solution
11-26-2020 05:21 PM
LeandraGordon
Occasional Contributor

ArcGIS Pro version 2.4.0
I have a Python Toolbox script to reorder the layers in my Current Map as follows:

currentProject  = arcpy.mp.ArcGISProject("CURRENT")
currentMap = currentProject.listMaps()[0] # this assumes  one map
layers = currentMap.listLayers()
             
#LGA  the very bottom
SPATIALDATA_LYR= currentMap.listLayers('SPATIALDATA_LYR')[0]
LGA_LYR= currentMap.listLayers('LGA_LYR')[0]
currentMap.moveLayer(SPATIALDATA_LYR,LGA_LYR,"AFTER") # LGA below Spatial

#Property
SPATIALDATA_LYR= currentMap.listLayers('SPATIALDATA_LYR')[0]
PROPERTY_LYR= currentMap.listLayers('PROPERTY_LYR')[0]
currentMap.moveLayer(SPATIALDATA_LYR,PROPERTY_LYR,"AFTER") #Prop below spatial

# 13    UGB_LYR All UGB line work that overlaps the LGA Layer
SPATIALDATA_LYR= currentMap.listLayers('SPATIALDATA_LYR')[0]
UGB_LYR = currentMap.listLayers('UGB_LYR')[0]
currentMap.moveLayer(SPATIALDATA_LYR,UGB_LYR,"BEFORE") #above
    
# 12    HERITAGE_LYR    Join between SPATIALDATA and excel HEADERS
SPATIALDATA_LYR= currentMap.listLayers('SPATIALDATA_LYR')[0]
HERITAGE_LYR = currentMap.listLayers('HERITAGE_LYR')[0]
currentMap.moveLayer(SPATIALDATA_LYR,HERITAGE_LYR,"BEFORE") #above

    
# 11    TOP_10_LYR  Top 10 Sales
SPATIALDATA_LYR= currentMap.listLayers('SPATIALDATA_LYR')[0]
TOP_10_LYR = currentMap.listLayers('TOP_10_LYR')[0]
currentMap.moveLayer(SPATIALDATA_LYR,TOP_10_LYR,"BEFORE") #above

return

The Layers are being moved but the results seem to be quite random and the order in my debugging doesn't match the order shown in the Drawing Order pane

0 Kudos
2 Solutions

Accepted Solutions
LeandraGordon
Occasional Contributor

****crickets*****************

No this isn't the solution and I didn't accept it.

View solution in original post

0 Kudos
LeandraGordon
Occasional Contributor

Got it logged as a bug: https://my.esri.com/#/support/bugs/BUG-000138288

Excuse me coming across as a little whiney but I understand ESRI products in the USA are quite cheap per user, which explains why users in the US users tend to put up with a lot more. ESRI in Australia and elsewhere is VERY expensive per seat so we do expect things to pretty much, well, work.

View solution in original post

0 Kudos
6 Replies
LeandraGordon
Occasional Contributor

****crickets*****************

No this isn't the solution and I didn't accept it.

View solution in original post

0 Kudos
DanPatterson
MVP Notable Contributor

Not following your "random" and "order in the debugging" but at least you got some resolution so I will assume it worked? (posting the link would be nice)


... sort of retired...
LeandraGordon
Occasional Contributor

🤣***cackles loudly*** No it's been accepted as a bug by ESRI Australia and is now logged with ESRI USA. So no, no resolution. I'm waiting for the case to appear in MyESRI and I'll link to it there...with my other bug.

<rant> I'm reasonably new to ESRI and Pro (we are in the process of migrating from Mapinfo). In general I have found it pretty good if you want to do a one off map and upload it to the web (and spend a couple of days fiddling to make it look the way it should). If you want to automate via Arcpy or Model Builder it is very buggy, things just don't do what they say on the box. In my mind this isn't acceptable for something that, in Australia, costs a lot of money. The support we get from ESRI Australia is great but I am starting to see why:
1. QGIS is used a lot in smaller businesses, like local government.
2. Users haven't migrated to Pro.
</rant>

 

0 Kudos
DanPatterson
MVP Notable Contributor

MapInfo!  How old school 😉 .  One of my early favs.

<bored comments>

I wish they would update the global bug list more regularly!

Esri Support | ArcGIS Technical Support

And your correct answer still stands (and your current answer is even better).

As for python tools.  I prefer the conventional ones where you have a dialog to fill in the parameters.  You get to screen grab the parameter dialog for documentation purposes and if you want to do the fancy-schmancy validating thing, you can even do it there.  (note... the toolbox structure is changing if you haven't noticed... all the toolboxes in  the

C:\YourInstallFolder\Resources\ArcToolBox\toolboxes

are now folders with "stuff" inside and the *.tbx files might become a thing of the past.

You will get used to it, and things will change

<back to numpy>


... sort of retired...
LeandraGordon
Occasional Contributor

"You will get used to it, and things will change"
Getting my users to reorder the layers every time isn't such a big ask.
The bugs with Apply Symbology from Layer (bugs in a python toolbox, bugs when used in model builder) are another thing altogether. The commentary on Geonet also makes me think that this is an issue that has been going on for years.
If I can't get a decent automated workflow up and running my users will abandon ESRI except for a couple of licences to produce something fancy for presentations and that's it. That's a fair bit of $$. 

0 Kudos
LeandraGordon
Occasional Contributor

Got it logged as a bug: https://my.esri.com/#/support/bugs/BUG-000138288

Excuse me coming across as a little whiney but I understand ESRI products in the USA are quite cheap per user, which explains why users in the US users tend to put up with a lot more. ESRI in Australia and elsewhere is VERY expensive per seat so we do expect things to pretty much, well, work.

View solution in original post

0 Kudos