Help getting programmatically getting features Display Expression and Label

2614
1
02-20-2014 10:19 AM
RickeyTom
New Contributor II
There is some code in the following link to get the display text.

Re: How to get label text for each feature in vb.net
http://forums.arcgis.com/threads/61714-how-to-get-label-text-for-each-feature-in-vb.net

This seems like a lot of work to get a label for a the selected feature.
Is this really the only way to do it.

I looked through the samples looking for a C# equivalent of this sample.

What I actually need is some code that allows me to programmatically get

the Display->displayExpression
[[ATTACH=CONFIG]31642[/ATTACH]

This display could be simple text or an expression.

or Labels -> Text String->
[[ATTACH=CONFIG]31643[/ATTACH]
0 Kudos
1 Reply
DuncanHornby
MVP Notable Contributor
Rickey,

The VBA code shows you how to extract the display expression for every feature in the layer and prints it to debug window. You can easily adapt this to c#

Public Sub PrintDisplayExpressions()
    ' Get layer, assumed first in TOC and has a display expression set
    Dim pMXD As IMxDocument
    Set pMXD = ThisDocument
    Dim pMap As IMap
    Set pMap = pMXD.FocusMap
    Dim pLayer As ILayer
    Set pLayer = pMap.Layer(0)
    Dim pFeaturelayer As IFeatureLayer
    Set pFeaturelayer = pLayer
    Dim pDisplayString As IDisplayString
    Set pDisplayString = pFeaturelayer
    
    ' Print display string
    Dim pFeatureCursor As IFeatureCursor
    Set pFeatureCursor = pFeaturelayer.Search(Nothing, True)
    Dim pFeature As IFeature
    Set pFeature = pFeatureCursor.NextFeature
    Do While Not pFeature Is Nothing
        Debug.Print pDisplayString.FindDisplayString(pFeature)
        Set pFeature = pFeatureCursor.NextFeature
    Loop
End Sub


Duncan
0 Kudos