How to load abbreviation dictionary

136
2
Jump to solution
10-11-2018 12:28 AM
Highlighted
New Contributor II

Hello,

I want to load abbreviation dictionnary from a table with ArcGisPro sdk, when a new map is added to a project. I dont find any way (snippset) to do this.

I done in it with the ArcObjects (for Arcmap) some years ago.

Could someone help me ?

Thanks.

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Regular Contributor

Hi

It is a two step process to work with Abbreviation Dictionary. You first have to create the dictionary and add it to the Map definition and then apply the dictionary to a specific layer.

This method below creates a dictionary and adds it to the Active map's definition:

public void LoadDictionary()
        {
            //Get the map's defintion
            var mapDefn = MapView.Active.Map.GetDefinition();
            //Get the Map's Maplex labelling engine properties
            var mapDefnPlacementProps = mapDefn.GeneralPlacementProperties as CIMMaplexGeneralPlacementProperties;
          
            //Define the abbreaviations we need in an array           
            List<CIMMaplexDictionaryEntry> abbreviationDictionary = new List<CIMMaplexDictionaryEntry>
            {
                new CIMMaplexDictionaryEntry {
                Abbreviation = "Hts",
                Text = "Heights",
                MaplexAbbreviationType = MaplexAbbreviationType.Ending

             },
                new CIMMaplexDictionaryEntry
                {
                    Abbreviation = "Ct",
                    Text = "Text",
                    MaplexAbbreviationType = MaplexAbbreviationType.Ending

                }
                //etc
            };
            //The Maplex Dictionary - can hold multiple Abbreviation collections
            var maplexDictionary = new List<CIMMaplexDictionary>
            {
                new CIMMaplexDictionary {
                    Name = "NameEndingsAbbreviations",
                    MaplexDictionary = abbreviationDictionary.ToArray()
                }
               
            };
            //Set the Maplex Label Engine Dictionary property to the Maplex Dictionary collection created above.
            mapDefnPlacementProps.Dictionaries = maplexDictionary.ToArray();
            //Set the Map defintion
            MapView.Active.Map.SetDefinition(mapDefn);
        }

Second step, apply a specific abbreviation dictionary in the Map Definition to the layer:

var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First();
           
            QueuedTask.Run( () => {
                //Creates Abbreviation dictionary and adds to Map Defintion                               
                LoadDictionary();
                //Get the layer's definition
                var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
                //Get the label classes - we need the first one
                var listLabelClasses = lyrDefn.LabelClasses.ToList();
                var theLabelClass = listLabelClasses.FirstOrDefault();
                //Modify label Placement props to use abbreviation dictionary
                CIMGeneralPlacementProperties labelEngine = MapView.Active.Map.GetDefinition().GeneralPlacementProperties;
                theLabelClass.MaplexLabelPlacementProperties.DictionaryName = "NameEndingsAbbreviations";
                theLabelClass.MaplexLabelPlacementProperties.CanAbbreviateLabel = true;
                theLabelClass.MaplexLabelPlacementProperties.CanStackLabel = false;
                //Set the labelClasses back
                lyrDefn.LabelClasses = listLabelClasses.ToArray();
                //set the layer's definition
                featureLayer.SetDefinition(lyrDefn);
            });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks

Uma

View solution in original post

2 Replies
Highlighted
Esri Regular Contributor

Hi

It is a two step process to work with Abbreviation Dictionary. You first have to create the dictionary and add it to the Map definition and then apply the dictionary to a specific layer.

This method below creates a dictionary and adds it to the Active map's definition:

public void LoadDictionary()
        {
            //Get the map's defintion
            var mapDefn = MapView.Active.Map.GetDefinition();
            //Get the Map's Maplex labelling engine properties
            var mapDefnPlacementProps = mapDefn.GeneralPlacementProperties as CIMMaplexGeneralPlacementProperties;
          
            //Define the abbreaviations we need in an array           
            List<CIMMaplexDictionaryEntry> abbreviationDictionary = new List<CIMMaplexDictionaryEntry>
            {
                new CIMMaplexDictionaryEntry {
                Abbreviation = "Hts",
                Text = "Heights",
                MaplexAbbreviationType = MaplexAbbreviationType.Ending

             },
                new CIMMaplexDictionaryEntry
                {
                    Abbreviation = "Ct",
                    Text = "Text",
                    MaplexAbbreviationType = MaplexAbbreviationType.Ending

                }
                //etc
            };
            //The Maplex Dictionary - can hold multiple Abbreviation collections
            var maplexDictionary = new List<CIMMaplexDictionary>
            {
                new CIMMaplexDictionary {
                    Name = "NameEndingsAbbreviations",
                    MaplexDictionary = abbreviationDictionary.ToArray()
                }
               
            };
            //Set the Maplex Label Engine Dictionary property to the Maplex Dictionary collection created above.
            mapDefnPlacementProps.Dictionaries = maplexDictionary.ToArray();
            //Set the Map defintion
            MapView.Active.Map.SetDefinition(mapDefn);
        }

Second step, apply a specific abbreviation dictionary in the Map Definition to the layer:

var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First();
           
            QueuedTask.Run( () => {
                //Creates Abbreviation dictionary and adds to Map Defintion                               
                LoadDictionary();
                //Get the layer's definition
                var lyrDefn = featureLayer.GetDefinition() as CIMFeatureLayer;
                //Get the label classes - we need the first one
                var listLabelClasses = lyrDefn.LabelClasses.ToList();
                var theLabelClass = listLabelClasses.FirstOrDefault();
                //Modify label Placement props to use abbreviation dictionary
                CIMGeneralPlacementProperties labelEngine = MapView.Active.Map.GetDefinition().GeneralPlacementProperties;
                theLabelClass.MaplexLabelPlacementProperties.DictionaryName = "NameEndingsAbbreviations";
                theLabelClass.MaplexLabelPlacementProperties.CanAbbreviateLabel = true;
                theLabelClass.MaplexLabelPlacementProperties.CanStackLabel = false;
                //Set the labelClasses back
                lyrDefn.LabelClasses = listLabelClasses.ToArray();
                //set the layer's definition
                featureLayer.SetDefinition(lyrDefn);
            });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks

Uma

View solution in original post

Highlighted
New Contributor II

That's really what I needed.

Thanks a lot.

Reply
0 Kudos