4

I can't seem to make ApplySymbologyFromLayer work in ArcGIS Pro console, or in a scripting tool.

It works in an independant python script run in IDLE, but not when executed inside ArcGIS Pro GUI, neither from a scripting tool or the console.

For a basic "single symbol" symbology, this snippet should do the trick :

aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps(your_map_name)[0]

map.addDataFromPath(path/to/your/layer)

in_layer = map.listLayers(your_layer_name)[0]
symbology_layer = path/to/your/layer.lyrx
arcpy.management.ApplySymbologyFromLayer(in_layer, symbology_layer, None)

It doesn't matter weither I try to apply the symbology from a lyrx file or from a data layer present inside map. Changing arcpy.management.ApplySymbologyFromLayer to arcpy.ApplySymbologyFromLayer_management doesn't change the output either. Neither does replacing the "None" as a last argument of the function by #, or nothing.

When executed, these code blocks say they worked, but the symbology is unchanged on the map. However, it appears to be changed in the symbology tab.

Here, I have tried to apply a grey, 7 pt symbology to this layer currently in pink. It is still pink in the map, and in the TOC, but if you go in the symbology panel for this layer, you see the symbology it is supposed to have. enter image description here It looks like a bug to me for the symbology displayed on the map does not match the one you can see on the symbology panel.

Is there a way to make this command work when executed from within ArcGIS Pro console or from a scripting tool ?

I tried this at first using ArcGIS Pro 2.0. I recently updated to ArcGIS Pro 2.1, but the problem is still there. Also tried it on different computers and for different datas, and data types (points, lines, polygons)

0

3 Answers 3

2

This is still logged with ESRI as a bug: https://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEwODQ5Nw== Bug BUG-000108497 -Running the Apply Layer Symbology tool as a script in the Python window does not update the symbology in the map.

Still not fixed. Alternate solution is 'close and reopen the project' (??)

1
  • But - the bug seems a little better with Pro 2.8.1 - still testing
    – LeasMaps
    Oct 18, 2021 at 0:34
2

In order to get this to work in your scripts inside ArcGIS Pro, I discovered it is best or even vital to first add the layers to the ArcGIS Pro TOC / Map, instead of just referencing them via a created Feature Layer. See the code below for an example.

Using this approach, I have been able to successfully update the layer symbology using the ApplySymbologyFromLayer_management tool with scripts running as a tool from a toolbox within ArcGIS Pro.

in_layer = YOUR CODE TO CREATE in_layer
in_symbology_layer = YOUR CODE TO CREATE in_symbology_layer

aprx = arcpy.mp.ArcGISProject("CURRENT")

aprxMap = aprx.activeMap # NOTE(!): 'aprx.activeMap' is only supported from Pro 2.1 onwards!!! activeMap returns None if script is called outside a running application according to ArcGIS Pro Help.

aprxMap.addLayer(in_layer, "AUTO_ARRANGE")
in_layer = aprxMap.listLayers(in_layer.name)[0]

aprxMap.addLayer(in_symbology_layer, "AUTO_ARRANGE")
in_symbology_layer = aprxMap.listLayers(in_symbology_layer.name)[0]

in_layer = arcpy.ApplySymbologyFromLayer_management(in_layer,in_symbology_layer,update_symbology="MAINTAIN")[0]
10
  • 1
    Thank you so much for your answer. But adding the data to the map first is indeed what I've been doing. Sorry, my description was not specific enough, I added the whole "add your data to the map" bit to my question so there is no ambiguity anymore. Anyhow, if this works for you, maybe it is a problem with my computer/data, or something to do with my ArcGIS Pro version (2.0.1)
    – T Dog
    May 23, 2018 at 12:34
  • Two more remarks:
    – Marco_B
    May 23, 2018 at 14:03
  • 1
    So, updated my ArcGIS Pro, to version 2.1.3, and it still doesn't work. I'm going to add some screenshots to the question to document it as much as possible.
    – T Dog
    May 29, 2018 at 9:22
  • 1
    I'm really surprise. I don't see how the problem could come from my system. It really has the appearence of an ArcGIS Pro bug. Anyway, if it works in your project, I don't see another explanation either. I'll try to investigate a bit more, and if I fail to find anything, I'll close this question, as the problem doesn't seem to be reproductible. Thank you very much for your help anyway
    – T Dog
    May 30, 2018 at 12:46
  • 1
    Last comment: I personally have had bad experiences with the arcpy.ApplySymbologyFromLayer_management tool in Pro and large datasets based on Query Layers against an enterprise database (note: not a Geodatabase!). The performance of swapping out the symbology seems directly linear with the dataset size, causing huge delays with datasets with 10-100's million records. This happens even if you set the "update_symbology=MAINTAIN" option, which theoretically wouldn't require re-reading all symbol classes from disk in a full table scan (which seems to be happening). I don't see this issue in ArcMap
    – Marco_B
    May 30, 2018 at 15:21
0

Using ArcGIS Pro 2.6.1

I found that passing a layer object through the ApplySymbologyFromLayer() function, as the first arg, does not work. For whatever reason, you should pass a string through it. So basically change your line from:

in_layer = arcpy.ApplySymbologyFromLayer_management(in_layer,in_symbology_layer,update_symbology="MAINTAIN")[0]

to:

in_layer = arcpy.ApplySymbologyFromLayer_management(str(in_layer),in_symbology_layer,update_symbology="MAINTAIN")[0]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.