Pro 2.0 Bug "Apply Symbology From Layer" GeoProcessing Tool

5261
22
Jump to solution
07-18-2017 02:52 PM
ThomasCox
Occasional Contributor

Applying symbology from a .lyr or .lyrx file has been an on-going battle for me.  I had an earlier post describing a problem with 1.4.  I was able to get past that, but now find a different problem at 2.0.

I am in the process of upgrading a couple of applications from 1.4 to 2.0  I have encountered a problem when I attempt to apply the symbology of a .lyr or .lyrx file to a layer brought into the session by the application.  This had been working in 1.4

I wanted to see how Pro itself handled this by running the GeoProcessing Tool "Apply Symbology From Layer" interactively through native Pro.  I manually brought in a non symbolized grid layer into Pro.  I ran the tool and entered the grid layer as the input layer.  For the Symbology layer, I navigated to a .lyrx file that is built from a different but identically structured grid.  As soon as I finished browsing to this file and selected it, the "ApplySymbology From Layer" tool 'seized up'.

Regarding the .lyrx file.  I am able to add it directly to a pro-session with no problems and proper symbolization.  If I do this, I am able to run the Apply Symboloby From Layer tool interactively, using the just added grid (from the .lyrx) file as the symbol layer and the tool works. It appears the version 2.0 tool only works with fully qualified layers that have been added to the session and not with providing it .lyr or .lyrx files that point to and are symbolized the same way. 

I have a series of screen captures illustrating this experience with using the tool with a .lyrx file and then with a layer already added to Pro.

This image shows a non symbolized grid file added to Pro

non symbolized raster

This image shows trying to run the tool using a .lyrx file as the symbology layer source.  This image also shows the output screen from Visual Studio that captures how it behaved after adding the .lyrx file to the Symbology Layer input:

It simply seizes up.

As a test to make sure the .lyrx file I was using was healthy, I added it to the Pro session through the Add Data button. This image shows it successfully added:

The following image shows running the Apply Symboloby From Layer tool using the just added GRID from the .lyrx file. When I populate the Symbology Layer input, the tool does not misbehave:

The final image shows the initial non-symbolized grid now with the proper symbology.

This seems to confirm that the tool is not properly handling .lyrx files when provided as a the symbology source.

Any assistance is appreciated.  I will be unable to reply to any responses for a few days.

Thanks again.

0 Kudos
22 Replies
RichardHowe
Occasional Contributor III

This bug is very frustrating. I have also reprted

0 Kudos
MichaelLowry2
New Contributor II

How do I report it? I want to increase the demand.

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi Michael,

If you have organization account ask your organization ArcGIS administrator to assign privilege to register cases on myesri.com or contact your Esri distributor and they inform you how to do that.

0 Kudos
NobbirAhmed
Esri Regular Contributor

The expected result can be achieved by passing a flag to Geoprocessing.ExecuteToolAsync(...) method. Here is the code snippet:

// inputs: symbologyLayer could be a layer file (*.lyrx) or a layer in the map

var parameters = Geoprocessing.MakeValueArray(inputLayer, symbologyLayer);

// set flags

GPExecuteToolFlags flags = GPExecuteToolFlags.GPThread;

 

// call ExecuteToolAsync

var gp_result = await Geoprocessing.ExecuteToolAsync("ApplySymbologyFromLayer_management", parameters, null, null, null, flags);

GKmieliauskas
Esri Regular Contributor

Hi Nobbir,

GPExecuteToolFlags.GPThread is not documented, but it seems it works. Please add documentation to ProConcepts Geoprocessing · Esri/arcgis-pro-sdk Wiki · GitHub 

Thank you.

0 Kudos
NobbirAhmed
Esri Regular Contributor

Thanks for the suggestion - we'll document. 

0 Kudos
MichaelLowry2
New Contributor II

Can Geoprocessing.ExecuteToolAsync(...)  be accessed with Python via arcpy?

0 Kudos
MichaelLowry2
New Contributor II

Here is a workaround for Python:

current_project = arcpy.mp.ArcGISProject("CURRENT")
current_map = current_project.listMaps()[0]
symbology_layer = SymbologyPath + '\\FLO_scaled_graduated_symbol.lyrx'
new_lyr_file = arcpy.mp.LayerFile(symbology_layer)
new_lyr = new_lyr_file.listLayers()[0]
old_lyr = current_map.listLayers(original_network)[0]
old_lyr_name = old_lyr.name
new_lyr.updateConnectionProperties(new_lyr.connectionProperties, old_lyr.connectionProperties)
new_lyr.name = old_lyr_name
new_lyr_file.save()
current_map.insertLayer(old_lyr, new_lyr_file)
current_map.removeLayer(old_lyr)
0 Kudos
CarolynKeagle1
New Contributor II

Unfortunately, this seems to reset my outline widths and manual class divisions. 

0 Kudos
MichaelLowry2
New Contributor II

BUG-000106281 about this issue is apparently fixed for Pro SDK at release 2.3,

https://pro.arcgis.com/en/pro-app/get-started/release-notes.htm

but I still cannot apply symbology from a layer file to a layer in my map through a script tool in Pro.

I have tried both call methods:

arcpy.management.ApplySymbologyFromLayer(target_layer, symbology_layer)

arcpy.ApplySymbologyFromLayer_management(target_layer, symbology_layer)

And I have tried .lyr and .lyrx

I know it is a problem with Pro, because if I run the exact same script tool in ArcMap (10.3) it works properly.

Any information or suggestions?