|
POST
|
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
{
/// <summary>
/// Interaction logic for wdwSymbology.xaml
/// </summary>
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();
}
}
}
}
... View more
06-20-2019
06:43 AM
|
0
|
5
|
4025
|
|
POST
|
Hi Sean Jones, That is definitely helping and now I can get through the code with no errors, but....the symbology (from the layer file) still does not get applied. I've tested using some hard coded values. When I use the Apply Symbology tool in ArcPro and use the same layer/layer file combination, it works. But when doing it through code it doesn't. No errors.....just no results. The original symbology is still there. I've tried with both .lyr and .lyrx files. Any ideas?? var mva = Geoprocessing.MakeValueArray("GISWRKS1.WORKS.WAT_Hydrant", @"K:\DSM Shared\ArcMap Symbology\TEST\Editing Symbols\GISWRKS1.WORKS.WAT_Hydrant.lyrx");
var gpresult = await Geoprocessing.ExecuteToolAsync("ApplySymbologyFromLayer_management", mva);
... View more
06-19-2019
12:38 PM
|
1
|
0
|
4025
|
|
POST
|
Hi, I'm trying to update the layers of a map by running the ApplySymbologyFromLayer GeoProcessing tool through some .NET code. For a while, there was a reported BUG-000106281 about this, but it is apparently fixed in 2.3. But.....I still cannot get it to work. Is there something wrong with my code? All of my .lyr files are located on a network drive. I get a NULL Reference Exception at the .ExecuteToolAsync line. Thanks, 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;
}
... View more
06-19-2019
11:09 AM
|
0
|
30
|
12679
|
|
POST
|
Hi Eric. I will post on the ArcGIS Pro Forum first, and if that doesn't work out, then I'll submit a ticket. Thanks,
... View more
06-19-2019
11:05 AM
|
1
|
0
|
4363
|
|
POST
|
Hi Eric Anderson, Do you know if there is also an issue running ApplySymbologyFromLayer in C# code like the following: 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;
}
... View more
06-19-2019
10:28 AM
|
0
|
2
|
4628
|
|
POST
|
Hi, I have a button that edits selected features in the map. The code looks for selected features in specific layers, and then converts the values of certain fields from Imperial to Metric. It's fairly simple, but what I am noticing is that sometimes the edits do not take. I have a messagebox on editOperation.Execute() == true that displays, but even when it gets displayed sometimes the features are not actually updated. The user then just clicks the tool button again, with the same selection, and then it all goes through ok 99% of the time. Any ideas as to why it sometimes doesn't work?? My code is below.... This isn't the only tool that I have this problem with. I use the same methodology for my editing in all of them. If you don't see any issues with my code, could it possibly be a network/system issue?? We are using a versioned Enterprise Geodatabase. Thanks, namespace CalcMetric_ArcPro
{
internal class btnCalcMetric : Button
{
protected override void OnClick()
{
if (MessageBox.Show("This will convert INVERT, LENGTH and ELEVATION of selected features to metric. Are you sure you want to do this?", "Convert to metric?", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question) == System.Windows.MessageBoxResult.No)
return;
int counter = 0;
try
{
QueuedTask.Run(() =>
{
Map map = MapView.Active.Map;
var editOperation = new ArcGIS.Desktop.Editing.EditOperation();
editOperation.Name = "Convert to Metric";
editOperation.EditOperationType = EditOperationType.Long;
foreach (Layer layer in map.GetLayersAsFlattenedList().OfType<FeatureLayer>())
{
var currentLayer = map.FindLayers(layer.Name).FirstOrDefault() as BasicFeatureLayer;
switch (currentLayer.Name)
{
case "GISWRKS1.WORKS.GravitySewer":
if (currentLayer.SelectionCount > 0)
{
var selection = currentLayer.GetSelection();
IReadOnlyList<long> selectedOIDs = selection.GetObjectIDs();
var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
foreach (var oid in selectedOIDs)
{
insp.Load(currentLayer, oid);
if (!DBNull.Value.Equals(insp["LENGTH"]) && !DBNull.Value.Equals(insp["UPSTREAMINVERT"]) && !DBNull.Value.Equals(insp["DOWNSTREAMINVERT"]))
{
insp["UPSTREAMINVERT"] = Math.Round(Convert.ToDouble(insp["UPSTREAMINVERT"]) * .3048, 2);
insp["DOWNSTREAMINVERT"] = Math.Round(Convert.ToDouble(insp["DOWNSTREAMINVERT"]) * .3048, 2);
insp["LENGTH"] = Math.Round(Convert.ToDouble(insp["LENGTH"]) * .3048, 2);
editOperation.Modify(insp);
counter++;
}
else
MessageBox.Show("Sanitary GravityMain " + insp["FACILITYID"].ToString() + " has a NULL value for LENGTH/UPSTREAMID/DOWNSTREAMID.", "NULL value", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
}
}
break;
case "GISWRKS1.WORKS.ssGravityMain":
if (currentLayer.SelectionCount > 0)
{
var selection = currentLayer.GetSelection();
IReadOnlyList<long> selectedOIDs = selection.GetObjectIDs();
var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
foreach (var oid in selectedOIDs)
{
insp.Load(currentLayer, oid);
if (!DBNull.Value.Equals(insp["LENGTH"]) && !DBNull.Value.Equals(insp["UPSTREAMINVERT"]) && !DBNull.Value.Equals(insp["DOWNSTREAMINVERT"]))
{
insp["UPSTREAMINVERT"] = Math.Round(Convert.ToDouble(insp["UPSTREAMINVERT"]) * .3048, 2);
insp["DOWNSTREAMINVERT"] = Math.Round(Convert.ToDouble(insp["DOWNSTREAMINVERT"]) * .3048, 2);
insp["LENGTH"] = Math.Round(Convert.ToDouble(insp["LENGTH"]) * .3048, 2);
editOperation.Modify(insp);
counter++;
}
else
MessageBox.Show("Storm GravityMain " + insp["FACILITYID"].ToString() + " has a NULL value for LENGTH/UPSTREAMID/DOWNSTREAMID.", "NULL value", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
}
}
break;
case "GISWRKS1.WORKS.SAN_Manhole":
if (currentLayer.SelectionCount > 0)
{
var selection = currentLayer.GetSelection();
IReadOnlyList<long> selectedOIDs = selection.GetObjectIDs();
var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
foreach (var oid in selectedOIDs)
{
insp.Load(currentLayer, oid);
if (!DBNull.Value.Equals(insp["ELEVATION"]))
{
insp["ELEVATION"] = Math.Round(Convert.ToDouble(insp["ELEVATION"]) * .3048, 2);
editOperation.Modify(insp);
counter++;
}
else
MessageBox.Show("Sanitary Manhole " + insp["FACILITYID"].ToString() + " has a NULL value for ELEVATION.", "NULL value", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
}
}
break;
case "GISWRKS1.WORKS.ssMaintenanceHole":
if (currentLayer.SelectionCount > 0)
{
var selection = currentLayer.GetSelection();
IReadOnlyList<long> selectedOIDs = selection.GetObjectIDs();
var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
foreach (var oid in selectedOIDs)
{
insp.Load(currentLayer, oid);
if (!DBNull.Value.Equals(insp["ELEVATION"]))
{
insp["ELEVATION"] = Math.Round(Convert.ToDouble(insp["ELEVATION"]) * .3048, 2);
editOperation.Modify(insp);
counter++;
}
else
MessageBox.Show("Storm Manhole " + insp["FACILITYID"].ToString() + " has a NULL value for ELEVATION.", "NULL value", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
}
}
break;
case "GISWRKS1.WORKS.ssCatchBasin":
if (currentLayer.SelectionCount > 0)
{
var selection = currentLayer.GetSelection();
IReadOnlyList<long> selectedOIDs = selection.GetObjectIDs();
var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
foreach (var oid in selectedOIDs)
{
insp.Load(currentLayer, oid);
if (!DBNull.Value.Equals(insp["ELEVATION"]))
{
insp["ELEVATION"] = Math.Round(Convert.ToDouble(insp["ELEVATION"]) * .3048, 2);
editOperation.Modify(insp);
counter++;
}
else
MessageBox.Show("Catchbasin " + insp["FACILITYID"].ToString() + " has a NULL value for ELEVATION.", "NULL value", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
}
}
break;
}
}
//show message if editing was successfull
if (editOperation.Execute() == true)
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(counter.ToString() + " features updated.", "Convert to Metric Finished");
else
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("No features were updated.", "Convert to Metric Finished");
});
}
catch (Exception ex)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(ex.ToString());
}
}
}
}
... View more
06-19-2019
08:13 AM
|
0
|
0
|
521
|
|
POST
|
No, I get a different error, but following the steps here (https://support.esri.com/en/technical-article/000012659) seems to have fixed that problem. For two projects, I have successfully 're-built' them in VS by starting from scratch, but I really hope I don't have to do that for ALL of my other ArcMap projects I have made previously.
... View more
06-03-2019
10:28 AM
|
0
|
0
|
3796
|
|
POST
|
Hi Kimberly, Below is a screen shot of the 'Warning' (not an 'Error'). This is after doing a 'Rebuild' on the project. As you can see, it says 'Rebuild All succeded', but looking in the AddIns folder there is nothing there. I've also attached the Config.esriaddinx and the .vbproj files. One thing is that in the .vbproj I did NOT have to change the text to .11.targets like in the instructions. It was already like that. I did change the <AddInTargetVersion> to 10.4 though. Yes, I am using .NET 4.5 with the 10.4 SDK installed. Screenshot below....
... View more
05-30-2019
05:25 AM
|
0
|
2
|
3796
|
|
POST
|
Hi Kimberly McCarty, I thought I had this fixed, but another issue came up. I cannot seem to get these old 10.2 project to create the .esriAddIn file when I 'Rebuild' them. I am getting this error: Warning Unable to create .esriAddin; missing ESRI ArcGIS Add-in SDK component(s). AsBuilts_AddIn C:\Visual Studio\MODIFIED FOR CONTRACT DB\AsBuilts_AddIn\AsBuilts_AddIn\AsBuilts_AddIn.vbproj 234 I have found this link for what seems to be a similar problem, but following the instructions doesn't seem to help: https://community.esri.com/message/449786 Thanks,
... View more
05-29-2019
11:36 AM
|
0
|
4
|
3796
|
|
POST
|
Thanks Kimberly, I tried updating the references as you suggested, but that still didn't work. So then I did this: 1. Uninstall 10.4 SDK 2. Uninstall VS 2012 (so just 2015) 3. Reinstall 10.4 SDK Now all is good, and when I update the references they resolve all the errors. Thanks for the help!!
... View more
05-29-2019
08:35 AM
|
0
|
5
|
3796
|
|
POST
|
Hi Kimberly, So what does it mean if you go to "Assemblies - Extensions" and you don't see any esri references listed?? I recently had my PC 'upgraded' to Windows 10, and when I got it back, my ArcObjects SDK is now using my VS 2015 install (instead of my VS 2012). All of my ArcObjects projects are now complaining of missing references, but I can't seem to figure out how to add them back. See my post here: https://community.esri.com/thread/234463-recent-upgrade-to-windows-10-messing-up-visual-studio-projects
... View more
05-28-2019
12:44 PM
|
0
|
0
|
4011
|
|
POST
|
Hi, So I just got my PC upgraded to Windows 10. I'm not sure how the IT department loaded everything. Previously I was using VS 2012, but now I have VS 2015. When I open up an old 2012 project I have all sort of missing references, but even after what appeared to be adding them back, I still have 195 "Errors" with my project. Any suggestions on how to fix this? A re-install of the SDK?? My ArcGIS 'templates' within VS seem to be there.
... View more
05-28-2019
11:31 AM
|
0
|
8
|
4203
|
|
POST
|
Hi Matt, I've been messing with this and this seems to work for me. Using the "Calculate GeometryAttributes_management" tool, I call the tool while I have features selected, and it updates the fields as specified in my 'args'. It seems like as long you have features selected, the GP Tool only processes the selected ones. See below: namespace GP_Test
{
internal class Button1 : Button
{
protected override void OnClick()
{
QueuedTask.Run(() =>
{
//****Get the the VLS layer.
var vlsLayer = MapView.Active.Map.FindLayers("GISWRKS1.WORKS.VLS_Points_FGDB").First() as BasicFeatureLayer;
//this is not necessary
var selection = vlsLayer.GetSelection();
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(selection.GetCount().ToString());
//run the GP tool
var args = Geoprocessing.MakeValueArray(vlsLayer, "COMMENTS POINT_X");
Geoprocessing.ExecuteToolAsync("CalculateGeometryAttributes_management", args);
});
}
}
}
... View more
05-17-2019
11:04 AM
|
2
|
1
|
4145
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-29-2026 07:40 AM | |
| 1 | 10-17-2023 07:40 AM | |
| 1 | 04-14-2026 08:54 AM | |
| 2 | 08-18-2023 08:57 AM | |
| 1 | 04-13-2018 10:07 AM |
| Online Status |
Offline
|
| Date Last Visited |
05-29-2026
09:43 AM
|