Select to view content in your preferred language

ApplySymbologyFromLayer toolbox Python script problem

2119
7
Jump to solution
12-13-2022 04:27 PM
by Anonymous User
Not applicable

arcpy.management.ApplySymbologyFromLayer() works from a standalone script, or the Arc Python window, but NOT from a toolbox script inside a map session. It executes without an error, but it doesn't change the symbology.

The only possible reason I can see is that the object type is a little different for a layer depending on whether it's a standalone/python window or the toolbox script.

standalone/python window layer type: <arcpy._mp.Layer object at 0x000001C3E7390C10>

toolbox script layer type: <MappingLayerObject object at 0x000001AEA43E2270>

Does anyone know what's going on?? I have run into other weird glitches with ArcGIS Pro where tools function differently in toolbox scripts, and it's very frustrating.

 

 

Script example that only works if run as a standalone script:

1.PNG

Tags (3)
1 Solution

Accepted Solutions
JohannesLindner
MVP Alum

From the tool doc:

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


Have a great day!
Johannes

View solution in original post

7 Replies
DanPatterson
MVP Esteemed Contributor

Are you using a custom toolbox where you can specify the parameter type from a dialog or is this a parameter-less tool?  A toolbox script will behave properly if you define the parameters in the tool and select them from the dialog like this?

tool.png


... sort of retired...
0 Kudos
by Anonymous User
Not applicable

I was grabbing the layers through the map.listLayers() method because one of them will be an in-memory layer that I created in my script, not a user input. 

But I just tried making them both user input parameters (Feature Layers), and it still didn't work.

0 Kudos
JohannesLindner
MVP Alum

From the tool doc:

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


Have a great day!
Johannes
by Anonymous User
Not applicable

Ahh, thanks! I guess I should have read the doc more thoroughly. I've been avoiding derived parameters, because I didn't understand them.  

Here's the code that works.

fix.PNG

fix2.PNG

0 Kudos
by Anonymous User
Not applicable

Actually, I found a better solution for my purposes. I was having an issue with the derived output adding a second copy of the layer being affected, when that layer was an in-memory layer. When I changed so that it wasn't added to the map at all until the derived output from the symbology tool, then I realized that the derived output doesn't get added to the map until the script ends. This is a problem because I need to apply symbology, and then edit it within the same script.

Here's the new method that works better when your affected layer is an in-memory layer: no duplication, and immediately added to map.

fix3.PNG

 

I know this seems like a pointless script... it's just a fragment of a larger script.

MichaelPorter
Emerging Contributor

This worked for me. Thanks!

0 Kudos
mody_buchbinder
Frequent Contributor

Hi

More or less the same code works for me when I take the source layer from lyrx file and not from the TOC

0 Kudos