Hi Dylan, See here for how to create a style: https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Map-Authoring#styles
"Style Items" are what is stored in style files. The base class is StyleItem: https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic12305.html . There is also more information here: https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Map-Authoring#style-item
The concrete style items are listed in the Inheritance Hierarchy on the API reference page (the link to the topic page above) and any, or all, of them can be stored in, or retrieved from, a .stylx. Specifically, in your case, where u want to store symbols in a style file, you want a SymbolStyleItem. https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/index.html#topic12405.html . SymbolStyleItem is used to wrap a CIMSymbol - whether custom or otherwise.
In this snippet I am using SymbolFactory to create 4 custom symbols - a point, line, poly, and text CIMSymbol - just using the defaults. Note how I wrap them in a SymbolStyleItem to add each of them to my style file. The only caveat is that the style file to which I am adding them must be in the project.
QueuedTask.Run(() => {
//make some (custom) symbols
var symbols = new List<CIMSymbol>();
symbols.Add(SymbolFactory.Instance.DefaultPointSymbol);
symbols.Add(SymbolFactory.Instance.DefaultLineSymbol);
symbols.Add(SymbolFactory.Instance.DefaultPolygonSymbol);
symbols.Add(SymbolFactory.Instance.DefaultTextSymbol);
//access the style file to be updated
var stylx_file = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(
item => item.Name == "My_Defaults");//must already be in the project
//make the style items that wrap the symbols
int p = 1;
int l = 1;
int pl = 1;
int t = 1;
foreach (var symbol in symbols) {
var key = "";
var category = "";
var itemType = StyleItemType.Unknown;
if (symbol is CIMPointSymbol ptSym) {
key = $"Point Symbol {p++}";
category = "Point";
itemType = StyleItemType.PointSymbol;
}
else if (symbol is CIMLineSymbol lnSym){
key = $"Line Symbol {l++}";
category = "Line";
itemType = StyleItemType.LineSymbol;
}
else if (symbol is CIMPolygonSymbol polySym) {
key = $"Polygon Symbol {pl++}";
category = "Polygon";
itemType = StyleItemType.PolygonSymbol;
}
else if (symbol is CIMTextSymbol textSym) {
key = $"Text Symbol {t++}";
category = "Text";
itemType = StyleItemType.TextSymbol;
}
else {
continue;//mesh
}
//make the symbol style item
var ssi = new SymbolStyleItem() {
Name = key,//Can be any string - localized is fine
Key = key,//must be unique
Tags = itemType.ToString(),//tag1;tag2;tag3;etc
Category = category,//arbitrary string for organizing your items
ItemType = itemType,//style item type
Symbol = symbol //your symbol
};
//add the style item
stylx_file.AddItem(ssi);
}
//copy an existing symbol into the style file
var arcgis_2d = Project.Current.GetItems<StyleProjectItem().FirstOrDefault(
item => item.Name == "ArcGIS 2D");
//get an arbitrary symbol, or symbols
var poly_ssi1 = arcgis_2d.SearchSymbols(StyleItemType.PolygonSymbol, "Glacier")[0];
var poly_ssi2 = arcgis_2d.SearchSymbols(StyleItemType.PolygonSymbol, "Buffered Gradient")[0];
//add them
stylx_file.AddItem(poly_ssi1);
stylx_file.AddItem(poly_ssi2);
//... etc ...
});
For more code snippets on how to access the various style items from a style file, please see the snippets here: https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-MapAuthoring#symbol-search
Result:
eg, the polygon symbols: