ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / StyleHelper Class / SearchSymbols Method
The StyleProjectItem to search.
The StyleItemType to search for. Search for point, line, polygon or text symbols.
The search term.
Example

In This Topic
    SearchSymbols Method
    In This Topic
    Returns a collection of symbol style items that satisfy the search criteria. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    styleProjectItem
    The StyleProjectItem to search.
    type
    The StyleItemType to search for. Search for point, line, polygon or text symbols.
    searchString
    The search term.

    Return Value

    A collection of SymbolStyleItem.
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run
    Example
    Create Line Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build 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));
    Polyline linePl = PolylineBuilderEx.CreatePolyline(plCoords);
    
    //Reference a line symbol in a style
    var ProjectStyles = Project.Current.GetItems<StyleProjectItem>();
    StyleProjectItem style = ProjectStyles.First(x => x.Name == "ArcGIS 2D");
    var symStyle = style.SearchSymbols(StyleItemType.LineSymbol, "Line with 2 Markers")[0];
    CIMLineSymbol lineSym = symStyle.Symbol as CIMLineSymbol;
    lineSym.SetSize(20);
    
    //Set symbolology, create and add element to layout
    //CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid);
    ElementFactory.Instance.CreateGraphicElement(
      container, linePl, lineSym, "New Line");
    
    Create Point Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D coord2D = new Coordinate2D(2.0, 10.0);
    
    //Reference a point symbol in a style
    StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>()
             .FirstOrDefault(item => item.Name == "ArcGIS 2D");
    SymbolStyleItem symStyleItm = stylePrjItm.SearchSymbols(
                          StyleItemType.PointSymbol, "City Hall")[0];
    CIMPointSymbol pointSym = symStyleItm.Symbol as CIMPointSymbol;
    pointSym.SetSize(50);
    
    var elemInfo = new ElementInfo()
    {
      CustomProperties = new List<CIMStringMap>() {
         new CIMStringMap() { Key = "Key1", Value = "Value1"},
         new CIMStringMap() { Key = "Key2", Value = "Value2"}
       },
      Anchor = Anchor.TopRightCorner,
      Rotation = 45.0
    };
    
    var graphic = GraphicFactory.Instance.CreateSimpleGraphic(
                                  coord2D.ToMapPoint(), pointSym);
    
    ElementFactory.Instance.CreateGraphicElement(
      container, graphic, "New Point", true, elemInfo);
    
    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 symbolology, create and add element to layout
    
      //An alternative simple symbol is also commented out below.
      //This would elminate 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 symbolology, create and add element to layout
    
      //An alternative simple symbol is also commented out below.
      //This would elminate 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");
    });
    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));
    }
    How to apply a point symbol from a style to a feature layer
      // var map = MapView.Active.Map;
      // if (map == null)
      //        return;
      // var pointFeatureLayer =
      //       map.GetLayersAsFlattenedList()
      //          .OfType<FeatureLayer>()
      //         .Where(fl => fl.ShapeType == esriGeometryType.esriGeometryPoint);
      //   await ApplySymbolToFeatureLayerAsync(pointFeatureLayer.FirstOrDefault(), "Fire Station");
    
      public Task ApplySymbolToFeatureLayerAsync(FeatureLayer featureLayer, string symbolName)
      {
        return QueuedTask.Run(async () =>
        {
          //Get the ArcGIS 2D System style from the Project
          var arcGIS2DStyle =
    Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 2D");
    
          //Search for the symbolName style items within the ArcGIS 2D style project item.
          var items = await QueuedTask.Run(() =>
          arcGIS2DStyle.SearchSymbols(StyleItemType.PointSymbol, symbolName));
    
          //Gets the CIMSymbol
          CIMSymbol symbol = items.FirstOrDefault().Symbol;
    
          //Get the renderer of the point feature layer
          CIMSimpleRenderer renderer = featureLayer.GetRenderer() as CIMSimpleRenderer;
    
          //Set symbol's real world setting to be the same as that of the feature layer
          symbol.SetRealWorldUnits(featureLayer.UsesRealWorldSymbolSizes);
    
          //Apply the symbol to the feature layer's current renderer
          renderer.Symbol = symbol.MakeSymbolReference();
    
          //Appy the renderer to the feature layer
          featureLayer.SetRenderer(renderer);
        });
      }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also