Select to view content in your preferred language

How to load abbreviation dictionary

983
2
Jump to solution
10-11-2018 12:28 AM
servicesigu
Occasional Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
UmaHarano
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
UmaHarano
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

servicesigu
Occasional Contributor

That's really what I needed.

Thanks a lot.

0 Kudos