Converting labels to map annotation for a single layer (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Interacting with and configuring maps, layers, and graphics > Working with labels and annotation > Converting labels to map annotation for a single layer (ArcObjects .NET 10.6 SDK)

Converting labels to map annotation for a single layer


About converting labels to map annotation for a single layer

This topic shows how to use the ConvertLabelsToAnnotation class to change a label for a single layer to map annotation. The ConvertLabelsToAnnotation class is a coarse-grained object that encapsulates the logic needed to perform this conversion. This class works with maps labeled with Maplex and the standard label engine.
The map reference passed into the function must be activated on a window. Check the IsMapActivated property on IActiveView to determine if the map is activated. Typically the map is activated unless it is opened via MapDocument or MapReader.
[C#]
static void ConvertLabelsToAnnotationSingleLayerMapAnno(IMap pMap, int layerIndex)
{
    IConvertLabelsToAnnotation pConvertLabelsToAnnotation=new
        ConvertLabelsToAnnotationClass();
    ITrackCancel pTrackCancel=new CancelTrackerClass();
    //Change global level options for the conversion by sending in different parameters to the next line.
    pConvertLabelsToAnnotation.Initialize(pMap,
        esriAnnotationStorageType.esriMapAnnotation,
        esriLabelWhichFeatures.esriVisibleFeatures, true, pTrackCancel, null);
    ILayer pLayer=pMap.get_Layer(layerIndex);
    IGeoFeatureLayer pGeoFeatureLayer=pLayer as IGeoFeatureLayer;
    if (pGeoFeatureLayer != null)
    {
        IFeatureClass pFeatureClass=pGeoFeatureLayer.FeatureClass;
        //Add the layer information to the converter object. Specify the parameters of the output annotation feature class here as well.
        pConvertLabelsToAnnotation.AddFeatureLayer(pGeoFeatureLayer,
            pGeoFeatureLayer.Name + "_Anno", null, null, false, false, false, false,
            false, "");
        //Do the conversion.
        pConvertLabelsToAnnotation.ConvertLabels();
        //Turn off labeling for the layer converted.
        pGeoFeatureLayer.DisplayAnnotation=false;
        //Refresh the map to update the display.
        IActiveView pActiveView=pMap as IActiveView;
        pActiveView.Refresh();
    }
}
[VB.NET]
Shared Sub ConvertLabelsToAnnotationSingleLayerMapAnno(ByVal pMap As IMap, ByVal layerIndex As Integer)
Dim pConvertLabelsToAnnotation As IConvertLabelsToAnnotation=New ConvertLabelsToAnnotationClass()
Dim pTrackCancel As ITrackCancel=New CancelTrackerClass()
'Change global level options for the conversion by sending in different parameters to the next line.
pConvertLabelsToAnnotation.Initialize(pMap, esriAnnotationStorageType.esriMapAnnotation, _
                                      esriLabelWhichFeatures.esriVisibleFeatures, True, _
                                      pTrackCancel, Nothing)

Dim pLayer As ILayer=pMap.Layer(layerIndex)
Dim pGeoFeatureLayer As IGeoFeatureLayer=pLayer

If Not pGeoFeatureLayer Is Nothing Then
    Dim pFeatureClass As IFeatureClass=pGeoFeatureLayer.FeatureClass
    
    'Add the layer information to the converter object. Specify the parameters of the output annotation feature class here as well.
    pConvertLabelsToAnnotation.AddFeatureLayer(pGeoFeatureLayer, pGeoFeatureLayer.Name + "_Anno", _
                                               Nothing, Nothing, False, False, False, False, False, "")
    
    'Do the conversion.
    pConvertLabelsToAnnotation.ConvertLabels()
    
    'Turn off labeling for the layer converted.
    pGeoFeatureLayer.DisplayAnnotation=False
    
    'Refresh the map to update the display.
    Dim pActiveView As IActiveView=pMap
    pActiveView.Refresh()
End If
End Sub






Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine