I hope this is the right place to post this question. I'm trying to change the selection color for a layer to red using the code below. Although I am able to generate a selection, the color for the features ends up being the default color (cyan).
foreach (var x in MapView.Active.Map.Layers)
{
if (x.Name == "Distribution Lines")
{
foreach (FeatureLayer fl in ((GroupLayer)x).Layers)
{
try
{
QueuedTask.Run(() =>
{
CIMBasicFeatureLayer cbm = (CIMBasicFeatureLayer)fl.GetDefinition();
cbm.SelectionColor = CIMColor.CreateRGBColor(255, 0, 0);
fl.Select(queryFilter, SelectionCombinationMethod.New);
});
}
catch (Exception ex)
{
}
}
}
}
Solved! Go to Solution.
I think you are missing the "SetDefinition" call on the layerdef. There is a snippet that shows what you want to do here:
Change the layer selection color
EDIT: sorry - looks like that snippet hasn't posted yet. This is it:
var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => {
// get the CIM definition of the layer
var layerDef = featureLayer.GetDefinition() as ArcGIS.Core.CIM.CIMBasicFeatureLayer;
// disable the default symbol
layerDef.UseSelectionSymbol = false;
// assign a new color
layerDef.SelectionColor = ColorFactory.RedRGB;
// apply the definition to the layer
featureLayer.SetDefinition(layerDef);
if (!featureLayer.IsVisible) featureLayer.SetVisibility(true);
//Do a selection
MapView.Active.SelectFeatures(MapView.Active.Extent);
});
I think you are missing the "SetDefinition" call on the layerdef. There is a snippet that shows what you want to do here:
Change the layer selection color
EDIT: sorry - looks like that snippet hasn't posted yet. This is it:
var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => {
// get the CIM definition of the layer
var layerDef = featureLayer.GetDefinition() as ArcGIS.Core.CIM.CIMBasicFeatureLayer;
// disable the default symbol
layerDef.UseSelectionSymbol = false;
// assign a new color
layerDef.SelectionColor = ColorFactory.RedRGB;
// apply the definition to the layer
featureLayer.SetDefinition(layerDef);
if (!featureLayer.IsVisible) featureLayer.SetVisibility(true);
//Do a selection
MapView.Active.SelectFeatures(MapView.Active.Extent);
});
After you change the Selection color try to use 'SetDefinition' on your FeatureLayer as in (from API reference guide):
public void SetDefinition(
)
GetDefinition only returns a copy of ArcGIS Pro's internal settings (not a reference), SetDefinition will then post your changes back to ArcGIS Pro.
Also you can find some samples dealing with the CIM here: https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Map-Authoring/CIMExamples