ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / SymbolExtensionMethods Class / SetRealWorldUnits Method
ArcGIS.Core.CIM.CIMSymbol
System.Boolean
Example

In This Topic
    SetRealWorldUnits Method
    In This Topic
    Sets whether symbol should be displayed with real world size or with fixed screen size.
    Syntax
    public static void SetRealWorldUnits( 
       CIMSymbol symbol,
       bool realWorldUnits
    )
    Public Shared Sub SetRealWorldUnits( _
       ByVal symbol As CIMSymbol, _
       ByVal realWorldUnits As Boolean _
    ) 

    Parameters

    symbol
    ArcGIS.Core.CIM.CIMSymbol
    realWorldUnits
    System.Boolean
    Remarks
    In 3D scenes if a symbol is set to display in real world units, the symbol will display bigger when camera is zoomed in closer to the symbol and will display smaller as the camera zooms away.
    Example
    How to apply a symbol from style to a feature layer
    public Task SetFeatureLayerSymbolFromStyleItemAsync(
               FeatureLayer ftrLayer, SymbolStyleItem symbolItem)
    {
      if (ftrLayer == null || symbolItem == null)
        throw new System.ArgumentNullException();
    
      return QueuedTask.Run(() =>
      {
        //Get simple renderer from the feature layer
        CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer;
        if (currentRenderer == null)
          return;
        //Get symbol from the SymbolStyleItem
        CIMSymbol symbol = symbolItem.Symbol;
    
        //Set symbol's real world setting to be the same as that of the feature layer
        symbol.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes);
    
        //Update the symbol of the current simple renderer
        currentRenderer.Symbol = symbol.MakeSymbolReference();
        //Update the feature layer renderer
        ftrLayer.SetRenderer(currentRenderer);
      });
    }
    
    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);
        });
      }
    How to apply a color ramp from a style to a feature layer
    public async Task ApplyColorRampAsync(FeatureLayer featureLayer, List<string> fields)
    {
    
        StyleProjectItem style =
            Project.Current.GetItems<StyleProjectItem>()
                .FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)");
        if (style == null) return;
        var colorRampList = await QueuedTask.Run(() => 
                    style.SearchColorRamps("Red-Gray (10 Classes)"));
        if (colorRampList == null || colorRampList.Count == 0) return;
        CIMColorRamp cimColorRamp = null;
        CIMRenderer renderer = null;
        await QueuedTask.Run(() =>
        {
            cimColorRamp = colorRampList[0].ColorRamp;
            var rendererDef = new UniqueValueRendererDefinition(fields, null, cimColorRamp);
            renderer = featureLayer?.CreateRenderer(rendererDef);
            featureLayer?.SetRenderer(renderer);
        });
    
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also