private void UpdateColorLocking(StyleProjectItem style, StyleItemType type) { IList <SymbolStyleItem> items = style.SearchSymbols(type, String.Empty); foreach (var item in items) { var symbol = item.GetObject() as CIMMultiLayerSymbol; if (symbol == null) { continue; } if (item.Category.IndexOf("Frame") == 0) { if (symbol is CIMPointSymbol) { SetFramePrimitiveNames(symbol as CIMPointSymbol, item.Key); } } else if (item.Category.IndexOf("Main Icon") != -1 || item.Category.IndexOf("Modifier 1") != -1 || item.Category.IndexOf("Modifier 2") != -1) { SetIconPrimitiveNames(symbol as CIMPointSymbol, true); } // update the symbol item.SetObject(symbol); style.UpdateItem(item); } }
protected async override void OnClick() { // To use this utility, you need to add the style that you want to update to your ArcGIS Pro project // If necessary and not alreadly listed, update the line below to include the name of the style that // you want to update // Note: no ".stylx" extension List <string> stylxFiles = new List <string>() { "mil2525d", "mil2525c", "app6b" }; string stylxUpdatedNames = string.Empty; foreach (string stylxToUpdateName in stylxFiles) { StyleProjectItem projectStyleItem = null; try { projectStyleItem = Project.Current.GetItems <StyleProjectItem>().First(x => x.Name == stylxToUpdateName); } catch (Exception ex) { projectStyleItem = null; } if (projectStyleItem == null) { continue; } stylxUpdatedNames += stylxToUpdateName + ";"; //update point symbols var ptSymbols = await projectStyleItem.SearchSymbolsAsync(StyleItemType.PointSymbol, ""); await QueuedTask.Run(() => { foreach (SymbolStyleItem s in ptSymbols) { CIMPointSymbol symbol = (CIMPointSymbol)s.Symbol; if (symbol == null) { continue; } try { var lyrs = symbol.SymbolLayers; foreach (CIMVectorMarker x in lyrs) { if (x.ScaleSymbolsProportionally == false) { x.ScaleSymbolsProportionally = true; } } symbol.SymbolLayers = lyrs; s.Symbol = symbol; projectStyleItem.UpdateItem(s); } catch (Exception ex2) { } } }); //update line symbols var lineSymbols = await projectStyleItem.SearchSymbolsAsync(StyleItemType.LineSymbol, ""); await QueuedTask.Run(() => { foreach (SymbolStyleItem s in lineSymbols) { try { if (s.Symbol is CIMLineSymbol) { CIMLineSymbol symbol = (CIMLineSymbol)s.Symbol; var lyrs = symbol.SymbolLayers; foreach (CIMSymbolLayer lyr in lyrs) { CIMVectorMarker x = lyr as CIMVectorMarker; if (x != null) { if (x.ScaleSymbolsProportionally == false) { x.ScaleSymbolsProportionally = true; } } } symbol.SymbolLayers = lyrs; s.Symbol = symbol; } else if (s.Symbol is CIMPointSymbol) { CIMPointSymbol symbol = (CIMPointSymbol)s.Symbol; var lyrs = symbol.SymbolLayers; foreach (CIMSymbolLayer lyr in lyrs) { CIMVectorMarker x = lyr as CIMVectorMarker; if (x != null) { if (x.ScaleSymbolsProportionally == false) { x.ScaleSymbolsProportionally = true; } } } symbol.SymbolLayers = lyrs; s.Symbol = symbol; s.ItemType = StyleItemType.LineSymbol; } projectStyleItem.UpdateItem(s); } catch (Exception ex3) { } } }); //update polygon symbols var polygonSymbols = await projectStyleItem.SearchSymbolsAsync(StyleItemType.PolygonSymbol, ""); await QueuedTask.Run(() => { foreach (SymbolStyleItem s in polygonSymbols) { try { if (s.Symbol is CIMPolygonSymbol) { CIMPolygonSymbol symbol = (CIMPolygonSymbol)s.Symbol; var lyrs = symbol.SymbolLayers; foreach (CIMSymbolLayer lyr in lyrs) { CIMVectorMarker x = lyr as CIMVectorMarker; if (x != null) { if (x.ScaleSymbolsProportionally == false) { x.ScaleSymbolsProportionally = true; } } } symbol.SymbolLayers = lyrs; s.Symbol = symbol; } else if (s.Symbol is CIMPointSymbol) { CIMPointSymbol symbol = (CIMPointSymbol)s.Symbol; var lyrs = symbol.SymbolLayers; foreach (CIMSymbolLayer lyr in lyrs) { CIMVectorMarker x = lyr as CIMVectorMarker; if (x != null) { if (x.ScaleSymbolsProportionally == false) { x.ScaleSymbolsProportionally = true; } } } symbol.SymbolLayers = lyrs; s.Symbol = symbol; s.ItemType = StyleItemType.PolygonSymbol; } projectStyleItem.UpdateItem(s); } catch (Exception ex3) { } } }); } // end foreach if (string.IsNullOrEmpty(stylxUpdatedNames)) { string stylxs = string.Join(";", stylxFiles); ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Could not find any styles: " + stylxs + " in Project"); } else { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Stylx Update DONE, styles updated:" + stylxUpdatedNames); } } // OnClick