I am applying symbology from a layer using the code snippet at https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-MapAuthoring#apply-symbology-to-a-layer-from.... When I use this method to update the symbology for a point layer, the symbols are updated but the symbol classes are maintained; the equivalent of 'maintain ranges' in the ApplySymbologyFromLayer tool. I would like for the symbol classes to be updated to only show the classes that are existent in the current data. Not all the classes from the symbology layer file. The equivalent of this in the ApplySymbologyFromLayer tool would be 'update ranges' and when I run this tool in Pro using 'update ranges', it does what I want.
So the question is how can I use the code below to update symbology ranges and not just maintain them?
var lyrDocFromLyrxFile = new LayerDocument(layerFile);
var cimLyrDoc = lyrDocFromLyrxFile.GetCIMLayerDocument();
var rendererFromLayerFile = ((CIMFeatureLayer)cimLyrDoc.LayerDefinitions[0]).Renderer as CIMUniqueValueRenderer;
featureLayer?.SetRenderer(rendererFromLayerFile);
@CharlesMacleod @Wolf @UmaHarano
Solved! Go to Solution.
I see, then it would have to be done by hand then - as in, rebuild the renderer with the updated classes and current symbology. I can ask the mapping team if there is a way to extend Recalc renderer (or provide a new method) that can retain the current symbology.
can you try doing a RecalculateRenderer(false)....(use "true" if you can have more than 100 unique values and want them all in the legend)
When I do RecalculateRenderer(false), it overwrites the point symbols retrieved from the layer file and replaces them with default point symbols which is not what I am looking to do.
I see, then it would have to be done by hand then - as in, rebuild the renderer with the updated classes and current symbology. I can ask the mapping team if there is a way to extend Recalc renderer (or provide a new method) that can retain the current symbology.