Select to view content in your preferred language

Apply Symbology not working inside toolbox python script

133
2
Jump to solution
3 weeks ago
BrandonMcAlister
Frequent Contributor

Hey everyone,

I have a python script that I wrote which creates a feature class and overwrites a feature class in my geodatabase then overwrites a feature on my enterprise portal. (11.1) Arc Pro Version 3.2. 

 

The issue I have is that this piece of code executes perfectly in the python window, and in a notebook. It will run in the toolbox with no errors but not update the single symbol symbology. I found a bug from 2021 but I am unsure if it was solved.

#Apply Symbology to new layer
symbol = MP.listLayers("Symbology")[0]
Publish = MP.listLayers("Active_DN_Inspections")[0] #creates variable for layer
arcpy.management.ApplySymbologyFromLayer(
    in_layer = Publish,
    in_symbology_layer = symbol,
    symbology_fields = None,
    update_symbology = "DEFAULT"
)

https://support.esri.com/en-us/bug/applysymbologyfromlayer-in-a-python-script-in-arcgis-pr-bug-00011...

https://community.esri.com/t5/arcgis-pro-questions/applysymbologyfromlayer-management-inside-toolbox... 

Thanks,
Brandon
0 Kudos
1 Solution

Accepted Solutions
TonyAlmeida
Frequent Contributor

The symbology created in a script tool, the tool must include the layer as a derived output parameter.

View solution in original post

0 Kudos
2 Replies
TonyAlmeida
Frequent Contributor

The symbology created in a script tool, the tool must include the layer as a derived output parameter.

0 Kudos
BrandonMcAlister
Frequent Contributor

@TonyAlmeida

After much trouble and research I was able to get it to work by doing this:

 

results = []
res = arcpy.management.ApplySymbologyFromLayer(
    in_layer = Publish,
    in_symbology_layer = symbol,
    symbology_fields = None,
    update_symbology = "DEFAULT"
)
results.append(res)
arcpy.SetParameter(2, results)

 

where parameter 2 is set up like this:

Label: OutputLayer

Data Type: Layer

Type: Derived

Direction: Output

 

Thanks,
Brandon
0 Kudos