I am trying to apply symbology to a feature class in ArcGIS Pro using python. When I use the following code in arcgis pro python window, it works fine and create a new symbology layer in the content pane with name "feature_class_Layer1" but the same python stand-alone code in visual studio does not give any output even though it runs without an error. The feature class in file geodatabase is still without any symbology when I open it to content pane.
Any suggestion?
Code lines:
import arcpy
arcpy.env.workspace = r"C:\path\to\the\geodatabase.gdb"
symbology_layer = r"C:\path\to\the\symbology.lyrx"
arcpy.management.ApplySymbologyFromLayer("feature_class", symbology_layer)
1 Answer 1
You are not understanding the difference between a feature class and a layer.
Feature Class is the data sitting in your geodatabase in some folder on your computer, a layer is the visualisation of that Feature Class. Layers exist in maps and maps only exist in projects. Where in your code that you run in visual studio do you reference the project with the map that you intend to insert the layer into? You do not. So your code runs and the layer is in memory until the code completes, you have not added it to the map.
Your code needs to get a handle on a map to insert the layer you created, suggest you explore the getting started page then the code samples for the map class.