3

Using an ArcPy script run from a toolbox, I want to import a feature class from a geodatabase into an ArcGIS Pro 2.1.2 map and then symbolise that layer based on a lyrx file stored on disk.

Here is a simplified version:

import arcpy, os
aprx = arcpy.mp.ArcGISProject('CURRENT')
m = aprx.listMaps('*')[0]
outputWorkspace = r"C:\Path\To\MyProject.gdb"
arcpy.env.workspace = outputWorkspace
out_fc = "fc_data"
out_fc_p = os.path.join(outputWorkspace, out_fc)
ref_lyrx = r"C:\Path\To\symbol_ref.lyrx"
m.addDataFromPath(out_fc_p)
out_fc_lyr = m.listLayers()[0]
arcpy.ApplySymbologyFromLayer_management(out_fc_lyr, ref_lyrx)

The script completes without error but no visible change is made to the symbology.

Is this a bug?

I've reviewed many similar questions but have been unable to resolve this.

I tried also first converting the fc to a layer using arcpy.MakeFeatureLayer_management().getOutput() before adding to the map with m.addLayer() and then using arcpy.ApplySymbologyFromLayer_management() but get exactly the same outcome.

6
  • 1
    What happens if you hit refresh?
    – Midavalo
    Commented Jun 14, 2018 at 4:12
  • Yep, manually refreshing doesn't change anything. Also, it seems that the RefreshActiveView function from ArcMap has not been implemented in Pro so I can't implement it in the script.
    – smh
    Commented Jun 14, 2018 at 4:24
  • 1
    Have you tried manually adding a layer to your map and running just the arcpy.ApplySymbologyFromLayer() from the command line? Does that work?
    – Midavalo
    Commented Jun 14, 2018 at 4:28
  • 1
    Yes, same result - the line runs (no error) but symbology still not updated, which leads me to think it may be a bug?...
    – smh
    Commented Jun 14, 2018 at 4:37
  • How precisely did you turn the code snippet that you have presented into "an ArcPy script run from a toolbox"? As a test, have you tried giving a path to your *.aprx when you create the ArcGISProject object, and then saving aprx at the end to see whether the rest of your code works that way?
    – PolyGeo
    Commented Jun 14, 2018 at 22:52

1 Answer 1

-1

yes, that looks like a bug. Had the exact same issue https://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEyMDkwNg==

1
  • The bug you've linked to is to do with ModelBuilder and there's no suggestion in the question that ModelBuilder is part of the workflow.
    – PolyGeo
    Commented Mar 9, 2021 at 5:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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