Hi Gintautas Kmieliauskas,
Great, thanks! Things are working even better now. I can apply symbology through the code now, but it only works some of the time. If I only have one layer in my map, it works. But with multiple layers I run into problems. See example screenshots below, and the code is at the very bottom.
1. I add layers. They get the default symbology.
2. I want to apply custom symbology, so I click on my "Map Symbology" tool, pick a symbology ("Edit" in this case), and then click 'Symbolize'. The code runs, but only some of the layers get symbolized.
3. Only 2 of the 4 layers get the symbology applied. In the window I can see the name of each layer as it loops through them, and all 4 are hit, but only 2 get changed. The required 4 .lyr files are located in the network path in the code.
4. I then manually use the Apply Symbology from Layer GP Tool, to update the other layers. Basically doing the same thing that my the code should be doing. Manually it works.
Any ideas as to why this only works sometimes and not all the time??
Here is the code. It's a very simple loop.
namespace SymbologyTool_ArcPro
{
public partial class wdwSymbology : ProWindow
{
public wdwSymbology()
{
InitializeComponent();
}
async private void btnSymbolize_Click(object sender, RoutedEventArgs e)
{
try
{
Map map = MapView.Active.Map;
pBar.Minimum = 0;
pBar.Maximum = map.Layers.Count;
this.Cursor = Cursors.Wait;
GPExecuteToolFlags flags = GPExecuteToolFlags.GPThread;
foreach (Layer layer in map.GetLayersAsFlattenedList().OfType<FeatureLayer>())
{
lblLayerName.Content = layer.Name.ToString();
var mva = Geoprocessing.MakeValueArray(layer.Name.ToString(), @"K:\DSM Shared\ArcMap Symbology\10.2 Schema\Editing Symbols\" + layer.Name.ToString() + ".lyr");
var gpresult = await Geoprocessing.ExecuteToolAsync("ApplySymbologyFromLayer_management", mva, null, null, null, flags);
pBar.Value = pBar.Value + 1;
}
}
catch (Exception ex)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(ex.ToString());
}
finally
{
this.Cursor = Cursors.Arrow;
MessageBox.Show("DONE");
this.Close();
}
}
}
}