ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / SymbolStyleItem Class
Members Example

In This Topic
    SymbolStyleItem Class
    In This Topic
    Represents a symbol saved in a style.
    Object Model
    SymbolStyleItem ClassCIMSymbol Class
    Syntax
    Example
    Create point graphic with symbology
    //Create a simple 2D point graphic and apply an existing point style item as the symbology.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D point geometry  
      Coordinate2D coord2D = new Coordinate2D(2.0, 10.0);
    
      //(optionally) Reference a point symbol in a style
      StyleProjectItem ptStylePrjItm = Project.Current.GetItems<StyleProjectItem>()
                                    .FirstOrDefault(item => item.Name == "ArcGIS 2D");
      SymbolStyleItem ptSymStyleItm = ptStylePrjItm.SearchSymbols(
                                             StyleItemType.PointSymbol, "City Hall")[0];
      CIMPointSymbol pointSym = ptSymStyleItm.Symbol as CIMPointSymbol;
      pointSym.SetSize(50);
    
      //Set symbology, create and add element to layout
    
      //An alternative simple symbol is also commented out below.
      //This would eliminate the four optional lines of code above that
      //reference a style.
    
      //CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(
      //                  ColorFactory.Instance.RedRGB, 25.0, SimpleMarkerStyle.Star);  
      //At 2.x - GraphicElement ptElm =
      //                    LayoutElementFactory.Instance.CreatePointGraphicElement(
      //                                        layout, coord2D, pointSym);
    
      GraphicElement ptElm = ElementFactory.Instance.CreateGraphicElement(
                                     container, coord2D.ToMapPoint(), pointSym);
      ptElm.SetName("New Point");
    });
    Create line graphic with symbology
    //Create a simple 2D line graphic and apply an existing line
    //style item as the symbology.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2d line geometry
      List<Coordinate2D> plCoords = new List<Coordinate2D>();
      plCoords.Add(new Coordinate2D(1, 8.5));
      plCoords.Add(new Coordinate2D(1.66, 9));
      plCoords.Add(new Coordinate2D(2.33, 8.1));
      plCoords.Add(new Coordinate2D(3, 8.5));
      //At 2.x - Polyline linePl = PolylineBuilder.CreatePolyline(plCoords);
      Polyline linePl = PolylineBuilderEx.CreatePolyline(plCoords);
    
      //(optionally) Reference a line symbol in a style
      StyleProjectItem lnStylePrjItm = Project.Current.GetItems<StyleProjectItem>()
                                    .FirstOrDefault(item => item.Name == "ArcGIS 2D");
      SymbolStyleItem lnSymStyleItm = lnStylePrjItm.SearchSymbols(
                                    StyleItemType.LineSymbol, "Line with 2 Markers")[0];
      CIMLineSymbol lineSym = lnSymStyleItm.Symbol as CIMLineSymbol;
      lineSym.SetSize(20);
    
      //Set symbology, create and add element to layout
    
      //An alternative simple symbol is also commented out below.
      //This would eliminate the four optional lines of code above that
      //reference a style.
      //
      //CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(
      //         ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid);  
      //At 2.x - GraphicElement lineElm =
      //        LayoutElementFactory.Instance.CreateLineGraphicElement(
      //                                            layout, linePl, lineSym);
    
      GraphicElement lineElm = ElementFactory.Instance.CreateGraphicElement(
                                                  container, linePl, lineSym);
      lineElm.SetName("New Line");
    });
    Create rectangle graphic with simple symbology
    //Create a simple 2D rectangle graphic and apply simple fill and
    //outline symbols.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D envelope geometry
      Coordinate2D rec_ll = new Coordinate2D(1.0, 4.75);
      Coordinate2D rec_ur = new Coordinate2D(3.0, 5.75);
      //At 2.x - Envelope rec_env = EnvelopeBuilder.CreateEnvelope(rec_ll, rec_ur);
      Envelope rec_env = EnvelopeBuilderEx.CreateEnvelope(rec_ll, rec_ur);
    
      //Set symbology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
        ColorFactory.Instance.BlackRGB, 5.0, SimpleLineStyle.Solid);
      CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
        ColorFactory.Instance.GreenRGB, SimpleFillStyle.DiagonalCross, outline);
    
      //At 2.x - GraphicElement recElm =
      //           LayoutElementFactory.Instance.CreateRectangleGraphicElement(
      //                                                  layout, rec_env, polySym);
      //         recElm.SetName("New Rectangle");
      //
      GraphicElement recElm = ElementFactory.Instance.CreateGraphicElement(
        container, rec_env, polySym, "New Rectangle");
      //Or use Predefined shape
      GraphicElement recElm2 = ElementFactory.Instance.CreatePredefinedShapeGraphicElement(
                                container, PredefinedShape.Rectangle, rec_env, polySym, 
                                "New Rectangle2");
    });
    How to search for a specific item in a style
    public Task<SymbolStyleItem> GetSymbolFromStyleAsync(StyleProjectItem style, string key)
    {
      return QueuedTask.Run(() =>
      {
        if (style == null)
            throw new System.ArgumentNullException();
    
        //Search for a specific point symbol in style
        SymbolStyleItem item = (SymbolStyleItem)style.LookupItem(StyleItemType.PointSymbol, key);
        return item;
      });
    }
    How to search for point symbols in a style
    public Task<IList<SymbolStyleItem>> GetPointSymbolsFromStyleAsync(StyleProjectItem style, string searchString)
    {
      if (style == null)
        throw new System.ArgumentNullException();
    
      //Search for point symbols
      return QueuedTask.Run(() => style.SearchSymbols(StyleItemType.PointSymbol, searchString));
    }
    How to search for line symbols in a style
    public Task<IList<SymbolStyleItem>> GetLineSymbolsFromStyleAsync(StyleProjectItem style, string searchString)
    {
      if (style == null)
        throw new System.ArgumentNullException();
    
      //Search for line symbols
      return QueuedTask.Run(() => style.SearchSymbols(StyleItemType.LineSymbol, searchString));
    }
    How to search for polygon symbols in a style
    public async Task<IList<SymbolStyleItem>> GetPolygonSymbolsFromStyleAsync(StyleProjectItem style, string searchString)
    {
      if (style == null)
        throw new System.ArgumentNullException();
    
      //Search for polygon symbols
      return await QueuedTask.Run(() => style.SearchSymbols(StyleItemType.PolygonSymbol, searchString));
    }
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
          ArcGIS.Desktop.Mapping.StyleItem
             ArcGIS.Desktop.Mapping.SymbolStyleItem

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also