Hi,
I'm trying to figure out how to update a layers symbology using an existing .lyr file. I can use the code below to add the layer file, but when I've already got the layer in my map all I really need to do is update the symbology.
QueuedTask.Run(() =>
{
Uri myUri = new Uri(@"K:\DSM Shared\ArcMap Symbology\10.2 Schema\Editing Symbols\GISWRKS1.WORKS.WAT_Hydrant.lyr");
Layer newLayer = LayerFactory.Instance.CreateFeatureLayer(myUri, MapView.Active.Map, LayerPosition.AddToTop);
}
);
Any guidance is appreciated.
Thanks,
Hi Robert LeClair
So I've been trying to use the Geoprocessing.ExecuteToolAsync("ApplySymbologyFromLayer_management"....) method for applying a .lyr/.lyrx file to a layer. According to all the documentation this should work, but I cannot get it to work as a C# add-in, or using a simple Python script. Can you confirm if there are any issues with this tool and how it works?? I've spent a lot of time on this already and don't want to continue if there are known issues.
See Building proper syntax for importing .lyr symbology for Feature Layer .
async private void btnSymbolize_Click(object sender, RoutedEventArgs e)
{
try
{
//QueuedTask.Run(() =>
//{
// Uri myUri = new Uri(@"K:\DSM Shared\ArcMap Symbology\10.2 Schema\Editing Symbols\GISWRKS1.WORKS.WAT_Hydrant.lyr");
// Layer newLayer = LayerFactory.Instance.CreateFeatureLayer(myUri, MapView.Active.Map, LayerPosition.AddToTop);
//}
//);
//var parameters = Geoprocessing.MakeValueArray("GISWRKS1.WORKS.WAT_Hydrant.lyr", @"K:\DSM Shared\ArcMap Symbology\TEST\Editing Symbols\GISWRKS1.WORKS.WAT_Hydrant.lyrx");
//var gpresult = await Geoprocessing.ExecuteToolAsync("ApplySymbologyFromLayer_management", new string[] { "GISWRKS1.WORKS.WAT_Hydrant", @"K:\DSM Shared\ArcMap Symbology\10.2 Schema\Editing Symbols\GISWRKS1.WORKS.WAT_Hydrant.lyr" });
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>())
{
var gpresult = await Geoprocessing.ExecuteToolAsync("ApplySymbologyFromLayer_management", new string[] { layer.Name.ToString(), @"K:\DSM Shared\ArcMap Symbology\10.2 Schema\Editing Symbols\" + layer.Name.ToString() + ".lyr" }, null, null, flags);
pBar.Value = pBar.Value + 1;
}
}
catch (Exception ex)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(ex.ToString());
}
finally
{
this.Cursor = Cursors.Arrow;
this.Close();
}
}
For anyone interested, it looks like there is a reported bug about this.