TransWikia.com

Making arcpy.ApplySymbologyFromLayer_management() work on CURRENT project of ArcGIS Pro

Geographic Information Systems Asked by Gustavo on December 24, 2020

I cannot make the ApplySymbologyFromLayer_management work on ArcGIS Pro by any means. The following code runs smoothly but does not give any results:

import arcpy

aprx = arcpy.mp.ArcGISProject("CURRENT")
aprxMap = aprx.activeMap
layer = aprxMap.listLayers()[0]
symblayer = r"C:referencelayer.lyrx"
arcpy.ApplySymbologyFromLayer_management(layers, symblayer)
aprx.save()

Any ideas?

One Answer

To test this in ArcGIS Pro 2.5.0 I used a project with one map and one polygon layer in it.

  1. I opened the project and gave the layer a very bright color, which was easy to distinguish from its original, and used Share | Layer File to save C:Tempreferencelayer.lyrx (I did not have permissions to save it as C:referencelayer.lyrx)
  2. I closed the project without saving.
  3. I restarted ArcGIS Pro with the same project and saw that the layer had its original colour
  4. I opened the Python window and typed in these commands in this order.

aprx = arcpy.mp.ArcGISProject("CURRENT")
aprxMap = aprx.activeMap
layer = aprxMap.listLayers()[0]
symblayer = r"C:Tempreferencelayer.lyrx"
arcpy.ApplySymbologyFromLayer_management(layer, symblayer)
  1. At this point the layer colour changed to be the very bright one obtained from the layer file.
  2. I then saved the project using ArcPy

aprx.save()
  1. I closed ArcGIS Pro and then re-opened the project.
  2. As expected the layer had the very bright colour.

I think the comment from @KHibma was probably correct in that the main difference between my code and yours is the attention I paid to using a variable named layer in two places rather than setting layer and then trying to retrieve a value from layers.

Answered by PolyGeo on December 24, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP