AnsweredAssumed Answered

ApplySymbologyFromLayer works in the Python window on ArcGIS Pro, but not in a ToolBox

Question asked by GustavoRTE on Jan 17, 2020
Latest reply on Jan 19, 2020 by lpinner

I am having this issue for months now, I am keeping up with the topics about it here, but no solution yet.

 

ApplySymbologyFromLayer does not work in a Python Toolbox. It does work on the Python window, but in a toolbox it does not show any result. No error, no warnings, just no effect at all. 

 

My Python toolbox code is decent sized, it has a number of tools and none of them have any issue, does a lot of different tasks, but for some reason, it can't Apply Symbology From Layer. When the line runs, I can see the layer being locked for a while, and then the code complete without any results.

 

There is one workround, which is constantly suggested here, and I was using successfully: 

 

new_lyr_file = arcpy.mp.LayerFile(symbology_layer)
new_lyr = new_lyr_file.listLayers()[0]
old_lyr = aprxMap.listLayers(inputlayer)[0]
old_lyr_name = old_lyr.name
new_lyr.updateConnectionProperties(new_lyr.connectionProperties, old_lyr.connectionProperties)
new_lyr.name = old_lyr_name
new_lyr_file.save()
aprxMap.insertLayer(old_lyr, new_lyr_file)
aprxMap.removeLayer(old_lyr)

Until i noticed that it screws up the URL in the Data Source. It brings some issues when trying to upload the Map to AGOL. 

 

The funny part is that both 

- arcpy.management.ApplySymbologyFromLayer(Input, Symbol)

and 

- arcpy.management.ApplySymbologyFromLayer(Input, Symbol)

lines of code works perfectly when using the Python Windom on ArcGIS Pro. 

 

Any ideas why the code would run in the Python Window but not on the Toolbox?

Outcomes