2

I created labels for layer in according with this example They display coded value description from domain, but I need value itself. I can resolve it manually by unchecking this option

"Layer's Properties -> Labels -> Expression... -> Display coded value description"

"Layer's Properties -> Labels -> Expression... -> Display coded value description"

How can I do that programmatically with ArcObjects 10+?

JGH
  • 41,794
  • 3
  • 43
  • 89

1 Answers1

3

Below is some VBA code to show you how to do this, key Interface is ICodedValueAttributes

Public Sub TurnONOFFCodedDescription()
    ' Get Document
    Dim pMXD As IMxDocument
    Set pMXD = ThisDocument

    ' Get map
    Dim pMap As IMap
    Set pMap = pMXD.FocusMap

    ' Get first layer and cast into IGeoFeatureLayer
    Dim pLayer As ILayer
    Set pLayer = pMap.Layer(0)
    Dim pGeoFL As IGeoFeatureLayer
    Set pGeoFL = pLayer

    ' Get annotation layer properties for this layer
    Dim pAnnotationPropertiesColl As IAnnotateLayerPropertiesCollection
    Set pAnnotationPropertiesColl = pGeoFL.AnnotationProperties
    Dim unplacedEle As IElementCollection
    Set unplacedEle = New ElementCollection
    Dim placedEle As IElementCollection
    Set placedEle = New ElementCollection
    Dim pAnnotateLayerProperties As IAnnotateLayerProperties
    pAnnotationPropertiesColl.QueryItem 0, pAnnotateLayerProperties, placedEle, unplacedEle

    ' Get label engine
    Dim pLabelEngineLayerProperties As ILabelEngineLayerProperties2
    Set pLabelEngineLayerProperties = pAnnotateLayerProperties
    Dim pAnnotationExpressionEngine As IAnnotationExpressionEngine
    Set pAnnotationExpressionEngine = pLabelEngineLayerProperties.ExpressionParser

    ' Set Coded value to be false (same as unchecking on GUI)
    Dim pCodedValueAttributes As ICodedValueAttributes
    Set pCodedValueAttributes = pAnnotationExpressionEngine
    pCodedValueAttributes.UseCodedValue = False
End Sub
Hornbydd
  • 43,380
  • 5
  • 41
  • 81