ArcGIS Pro 3.7 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
    {
      //Note: 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 symbology, create and add element to layout
      //CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid);
      ElementFactory.Instance.CreateGraphicElement(
        layout, linePl, lineSym, "New Line");
    }
    Create Point Element
    {
      //Note: 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(
        layout, 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.
      //Note: Must be on 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);  
    
      GraphicElement ptElm = ElementFactory.Instance.CreateGraphicElement(
                                     layout, 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.
      //Note: Must be on 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));
    
      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);  
    
    
      GraphicElement lineElm = ElementFactory.Instance.CreateGraphicElement(
                                                  layout, linePl, lineSym);
      lineElm.SetName("New Line");
    }
    How to apply a point symbol from a style to a feature layer
    {
          //Get the ArcGIS 2D System style from the Project
          var arcGIS2DStyle =
    Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 2D");
    
          //Note: Needs QueuedTask to run
          //Search for the symbolName style items within the ArcGIS 2D style project item.
          var items = arcGIS2DStyle.SearchSymbols(StyleItemType.PointSymbol, "Circle 1");
    
          //Gets the CIMSymbol
          CIMSymbol symbolToUse = 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
          symbolToUse.SetRealWorldUnits(featureLayer.UsesRealWorldSymbolSizes);
    
          //Apply the symbol to the feature layer's current renderer
          renderer.Symbol = symbolToUse.MakeSymbolReference();
    
          //Apply the renderer to the feature layer
          featureLayer.SetRenderer(renderer);
      }
    How to search for point symbols in a style
    {
        //Search for point symbols
        //Note: styleProjectItem was created above in the variable initialization section
        //Note: Needs QueuedTask to run
        //Search for point symbols
        styleProjectItem.SearchSymbols(StyleItemType.PointSymbol, "searchString");
    }
    How to search for line symbols in a style
    {
        //Note: styleProjectItem was created above in the variable initialization section
        //Note: Needs QueuedTask to run
        //Search for line symbols
        styleProjectItem.SearchSymbols(StyleItemType.LineSymbol, "searchString");
    }
    How to search for polygon symbols in a style
    {
        //Note: styleProjectItem was created above in the variable initialization section
        //Note: Needs QueuedTask to run
        //Search for polygon symbols
        styleProjectItem.SearchSymbols(StyleItemType.PolygonSymbol, "searchString");
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also