0

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)
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 23, 2024 at 9:00

1 Answer 1

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.

answered Aug 23, 2024 at 11:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.