Added your method to the code behind for a simple button Add-In. Added the appropriate references, for example IMap is an interface that comes from an ESRI provided assembly (ESRI.ArcGIS.Carto.dll):IMap (from ESRI Carto)Added the following references through Project > Add Reference in Visual Studio:ESRI.ArcGIS.CartoESRI.ArcGIS.GeodatabaseESRI.ArcGIS.DisplayNow on the buttons click we want to call this method passing in the appropriate arguments. With Add-ins we have access to a static class called ArcMap. This will represent our initial entry point as with 'ThisDocument', for example, with VBA. Here is an example of calling the method: protected override void OnClick() { ConvertLabelsToAnnotationSingleLayerMapAnno(ArcMap.Document.FocusMap, 0); .... The code will pass the Active map (dataframe) and the value of 0 to your method. This tells it to process on the first layer in the given map. The labels are sucessfully converted to Map annotation in a new annotation group.
protected override void OnClick() { ConvertLabelsToAnnotationSingleLayerMapAnno(ArcMap.Document.FocusMap, 0); ....
using System; using System.Collections.Generic; using System.Text; using System.IO; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.esriSystem; namespace ArcMapAddin2 { public class LabelToAnno : ESRI.ArcGIS.Desktop.AddIns.Button { public LabelToAnno() { } protected override void OnClick() { // // TODO: Sample code showing how to access button host // ConvertLabelsToAnnotationSingleLayerMapAnno(ArcMap.Document.FocusMap, 0); ArcMap.Application.CurrentTool = null; } 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(); } } } }
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(); }}
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.