1

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)

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]
  • 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 '18 at 12:34
  • Two more remarks: – Marco_B May 23 '18 at 14:03
  • Three more remarks: 1) I notice you set a None for the update_symbology String type option. Optional parameters which are the last ones in the list of parameters, do not have to be specified, so just leave that part out, or replace by e.g. "#", which is the way to specify parameters you don't want to enter. 2) I recommend you to rename either the "in_layer" or the "in_symbology_layer" if the layers happen to have the same name. Do this before adding them to the TOC! This will avoid naming ambiguity for the layers. 3) Definitely upgrade to the latest Pro edition. ESRI is still fully bug fixing. – Marco_B May 23 '18 at 14:11
  • Thanks for the tips ! Removing the None or replacing it with # doesn't make it work. My layers doesn't share a name, I'm sorry if that too wasn't clear : the "path/to/layer" and "path/to/layer.lyrx" were just placeholders. And, sadly, I don't have the admin rights on my computer. I will ask for the update to be done, and tell you how it went ! – T Dog May 23 '18 at 14:46
  • 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 '18 at 9:22

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.