How to convert labels to geodatabase annotation for a single layer

Converting labels to geodatabase annotation for a single layer

This document demonstrates how to use the ConvertLabelsToAnnotation class to change a label for a single layer to geodatabase 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 or the standard label engine.
The following code examples contain a Boolean option for making the annotation feature linked. Feature-linked annotation can only be created with an ArcEditor or higher license level.
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.
static void convertLabelsToGDBAnnotationEntireMap(IMap map, int layerIndex, boolean
    featureLinked)throws Exception{
    IConvertLabelsToAnnotation convertLabToAnno = new ConvertLabelsToAnnotation();
    ITrackCancel trackCancel = new CancelTracker();
    // Change global level options for the conversion by sending in
    // different parameters to the next line.
        esriLabelWhichFeatures.esriAllFeatures, true, trackCancel, null);

    ILayer layer = map.getLayer(layerIndex);
    IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)layer;
    if (geoFeatureLayer != null){
        IFeatureClass featureClass = geoFeatureLayer.getFeatureClass();
        IDataset dataset = new IDatasetProxy(featureClass);

        IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy
        // Add the layer information to the converter object. Specify the
        // parameters of the output annotation feature class here as well.
        convertLabToAnno.addFeatureLayer(geoFeatureLayer, geoFeatureLayer.getName() 
            + "_Anno", featureWorkspace, featureClass.getFeatureDataset(),
            featureLinked, false, false, true, true, "");

        // Do the conversion.
        IEnumLayer enumLayer = convertLabToAnno.getAnnoLayers();
        // Turn off labeling for the layer converted.

        // Add the result annotation layer to the map.
        map.addLayers(enumLayer, true);

        // Refresh the map to update the display.
        IActiveView activeView = (IActiveView)map;

Development licensingDeployment licensing
ArcGIS for Desktop BasicArcGIS for Desktop Basic
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine