using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.esriSystem; namespace ArcMapAddin2 { public class LabelToAnnotation : ESRI.ArcGIS.Desktop.AddIns.Button { public LabelToAnnotation() { } protected override void OnClick() { // // TODO: Sample code showing how to access button host // ConvertLabelsToAnnotationSingleLayerMapAnno(ArcMap.Document.FocusMap,0); } protected override void OnUpdate() { Enabled = ArcMap.Application != null; } 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(); } } } }
Solved! Go to Solution.