<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Label by attribute in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/label-by-attribute/m-p/1243181#M9204</link>
    <description>&lt;P&gt;The following snippet worked for me:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override async void OnClick()
{
  var fcLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().Where(fl =&amp;gt; fl.Name == "TestPoints").FirstOrDefault();
  await QueuedTask.Run(() =&amp;gt;
  {
    List&amp;lt;CIMLabelClass&amp;gt; newLabels = new List&amp;lt;CIMLabelClass&amp;gt;()
    { new CIMLabelClass
      {
        Name = "labelFeatureLayer",
        ExpressionEngine = LabelExpressionEngine.Arcade,
        Expression = "Geometry($feature).z",
        TextSymbol = SymbolFactory.Instance.ConstructTextSymbol().MakeSymbolReference(),
        Visibility = true
      }
    };
    var lyrDefn = fcLayer.GetDefinition() as CIMFeatureLayer;
    lyrDefn.LabelClasses = newLabels.ToArray();
    fcLayer.SetDefinition(lyrDefn);
    fcLayer.SetLabelVisibility(true);
  });
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/42133"&gt;@GKmieliauskas&lt;/a&gt;&amp;nbsp; is correct as there can be multiple labels with visibility.&amp;nbsp; &amp;nbsp;The snippet above removes all but the new label from the array of labels.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Dec 2022 05:49:59 GMT</pubDate>
    <dc:creator>Wolf</dc:creator>
    <dc:date>2022-12-22T05:49:59Z</dc:date>
    <item>
      <title>Label by attribute</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/label-by-attribute/m-p/1242923#M9202</link>
      <description>&lt;P&gt;Hi Everbody&lt;/P&gt;&lt;P&gt;I am trying to label a FeatureLayer with values from an attribute, but somehow it fails. I have calculated the z-value and want to label that, but for some&amp;nbsp;reason it label another attribute.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the CIMLabelClass I define the Expression to be the 'zValue' attribute:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var labelFeatureLayer = new CIMLabelClass
                        {
                            Name = "labelFeatureLayer",
                            ExpressionEngine = LabelExpressionEngine.Arcade,
                            Expression = "$feature.zValue",
                            TextSymbol = SymbolFactory.Instance.ConstructTextSymbol().MakeSymbolReference(),
                            Visibility = true
                        };


                        var lyrDefn = fcLayer.GetDefinition() as CIMFeatureLayer;
                        var listLabelClasses = lyrDefn.LabelClasses.ToList();
                        listLabelClasses.Add(labelFeatureLayer);
                        lyrDefn.LabelClasses = listLabelClasses.ToArray();
                        fcLayer.SetDefinition(lyrDefn);

                        fcLayer.SetLabelVisibility(true);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But its just showing a different attribute (in this case its the objectid)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Daniel4_0-1671629918077.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/59011i8716BB056E06D12A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Daniel4_0-1671629918077.png" alt="Daniel4_0-1671629918077.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2022 13:40:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/label-by-attribute/m-p/1242923#M9202</guid>
      <dc:creator>Daniel4</dc:creator>
      <dc:date>2022-12-21T13:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Label by attribute</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/label-by-attribute/m-p/1242940#M9203</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I think you need to switch off visibility for other existing label classes. Look at Esri community sample&amp;nbsp;&lt;A href="https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Map-Authoring/LabelLineFeatures" target="_self"&gt;LabelLineFeatures&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;                //Turn off all the label classes except this one
                foreach (var lc in listLabelClasses)
                {
                    lc.Visibility = lc.Name == "labelFeatureLayer" ? true : false;
                }&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 21 Dec 2022 14:42:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/label-by-attribute/m-p/1242940#M9203</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2022-12-21T14:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Label by attribute</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/label-by-attribute/m-p/1243181#M9204</link>
      <description>&lt;P&gt;The following snippet worked for me:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override async void OnClick()
{
  var fcLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().Where(fl =&amp;gt; fl.Name == "TestPoints").FirstOrDefault();
  await QueuedTask.Run(() =&amp;gt;
  {
    List&amp;lt;CIMLabelClass&amp;gt; newLabels = new List&amp;lt;CIMLabelClass&amp;gt;()
    { new CIMLabelClass
      {
        Name = "labelFeatureLayer",
        ExpressionEngine = LabelExpressionEngine.Arcade,
        Expression = "Geometry($feature).z",
        TextSymbol = SymbolFactory.Instance.ConstructTextSymbol().MakeSymbolReference(),
        Visibility = true
      }
    };
    var lyrDefn = fcLayer.GetDefinition() as CIMFeatureLayer;
    lyrDefn.LabelClasses = newLabels.ToArray();
    fcLayer.SetDefinition(lyrDefn);
    fcLayer.SetLabelVisibility(true);
  });
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/42133"&gt;@GKmieliauskas&lt;/a&gt;&amp;nbsp; is correct as there can be multiple labels with visibility.&amp;nbsp; &amp;nbsp;The snippet above removes all but the new label from the array of labels.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 05:49:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/label-by-attribute/m-p/1243181#M9204</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2022-12-22T05:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Label by attribute</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/label-by-attribute/m-p/1244754#M9219</link>
      <description>&lt;P&gt;Hi, thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried with your code&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/12882"&gt;@Wolf&lt;/a&gt;&amp;nbsp;but ArcGIS Pro doesn't&amp;nbsp; show the label.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The label tab dont show the new label class:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Daniel4_0-1672660750002.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/59596iE1C3C8D64937BF4C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Daniel4_0-1672660750002.png" alt="Daniel4_0-1672660750002.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But if I manual in ArcGis Pro create a label class (eg. 'test'), suddenly the new label class appires:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Daniel4_1-1672660974167.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/59597i43CAF00F9512DA54/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Daniel4_1-1672660974167.png" alt="Daniel4_1-1672660974167.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do I need to delete some Label Classes before? Or do I need do to something with 'Class 1'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 12:06:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/label-by-attribute/m-p/1244754#M9219</guid>
      <dc:creator>Daniel4</dc:creator>
      <dc:date>2023-01-02T12:06:38Z</dc:date>
    </item>
  </channel>
</rss>

