Update Maplevel of Representations not possible

1467
1
10-31-2013 07:32 AM
by Anonymous User
Not applicable
Original User: Hedwig

Updating the Maplevels of representations by code isn't possible.

I can by code change the Maplevel however the Symbol Levels Dialog doesn't show the changed Maplevels. In the Actieve View the inserted Maplevels aren't used neither. However exporting the, changed, Maplevels shows the by code changed Maplevels.
I'm able to change all other Symbology types and change the other options of the Representations.

Here's is the code for importing the Maplevels from a dictionary. The value of the dictionary is a list of symbol levels.
[ATTACH=CONFIG]28752[/ATTACH]

                 if (pGroupedLayer is IFeatureLayer & pGroupedLayer is ISymbolLevels & pGroupedLayer is IGeoFeatureLayer)
                {

                    layerName = pGroupedLayer.Name;

                    IGeoFeatureLayer pGeoFLayer = (IGeoFeatureLayer)pGroupedLayer;
                    ISymbolLevels pSymbLevels = (ISymbolLevels)pGeoFLayer;
                    pSymbLevels.UseSymbolLevels = true;

                    IFeatureRenderer pFeatRen = pGeoFLayer.Renderer;

                    if (pFeatRen is IRepresentationRenderer)
                    {
                        IRepresentationRenderer pRepRen = (IRepresentationRenderer)pFeatRen;

                        IRepresentationClass repClass = pRepRen.RepresentationClass;
                        IRepresentationRules pRepRules = repClass.RepresentationRules;

                        pRepRules.Reset();
                        int OutIdx = 0;
                        IRepresentationRule pRepRule;
                        pRepRules.Next(out OutIdx, out pRepRule);

                        IMapLevel pMapLevel;

                        while (!(pRepRule == null))
                        {
                            repName = pRepRules.get_Name(OutIdx).ToString();

                            if (_visualizationEntries.ContainsKey(layerName + repName))
                            {
                                visEntry = _visualizationEntries[layerName + repName];
                            }
                            List<int> lstSymbolLevels = visEntry.SymbolLevels;
                          
                            for (int k = 0; k < pRepRule.LayerCount; k++)
                            {

                                IBasicSymbol pRepLayer = pRepRule.get_Layer(k);
                                if (pRepLayer is IBasicMarkerSymbol)
                                {
                                    IBasicMarkerSymbol pBasMarkSym = (IBasicMarkerSymbol)pRepLayer;
                                    pMapLevel = (IMapLevel)pBasMarkSym;
                                    oldMapLevel = pMapLevel.MapLevel;

                                    newMapLevel = lstSymbolLevels;

                                    pMapLevel.MapLevel = newMapLevel;
                                    newMapLevel = pMapLevel.MapLevel;

                                 }
                                else if (pRepLayer is IBasicFillSymbol)
                                {
                                    IBasicFillSymbol pBasFillSym = (IBasicFillSymbol)pRepLayer;

                                    pMapLevel = (IMapLevel)pBasFillSym;
                                    oldMapLevel = pMapLevel.MapLevel;

                                    newMapLevel = lstSymbolLevels;
                                    pMapLevel.MapLevel = newMapLevel;
                                }
                                else if (pRepLayer is IBasicLineSymbol)
                                {
                                    IBasicLineSymbol pBasLineSym = (IBasicLineSymbol)pRepLayer;

                                    pMapLevel = (IMapLevel)pBasLineSym;
                                    oldMapLevel = pMapLevel.MapLevel;
                                    newMapLevel = lstSymbolLevels;

                                    pMapLevel.MapLevel = newMapLevel;
                                }
                                else
                                {
                                 }

                               }
                          pRepRules.Next(out OutIdx, out pRepRule);
                        } 
                  }    
           }
       }
  }

I also tried
                if (pLayer is IGeoFeatureLayer)
                {
                    pGeoFLayer = pLayer as IGeoFeatureLayer;
                    if (pGeoFLayer.Renderer is IRepresentationRenderer)
                    {

                        ISymbolLevels symLevels = (ISymbolLevels)pGeoFLayer;
                        symLevels.UseSymbolLevels = true;

                        IRepresentationRenderer oldRepRen = (IRepresentationRenderer)pGeoFLayer.Renderer;
                        IRepresentationClass oldRepClass = oldRepRen.RepresentationClass;
                        IRepresentationRules oldRepRules = oldRepClass.RepresentationRules;

                        Dictionary<IRepresentationRule, string> lstNewRules = new Dictionary<IRepresentationRule, string>();
                        oldRepRules.Reset();
                        int OutIdx = 0;
                        IRepresentationRule oldRepRule, newRepRule;
                        oldRepRules.Next(out OutIdx, out oldRepRule);


                        while (!(oldRepRule == null))
                        {
                            newRepRule = new RepresentationRuleClass();

                            string oldRepName = oldRepRules.get_Name(OutIdx).ToString();

                            for (int L = 0; L < oldRepRule.LayerCount; L++)
                            {
                                IBasicSymbol oldSymbol = oldRepRule.get_Layer(L);
                                if (oldSymbol is IMapLevel)
                                {
                                    if (oldSymbol is IBasicLineSymbol)
                                    {
                                        IBasicLineSymbol oldBasicLine = (IBasicLineSymbol)oldSymbol;
                                        IMapLevel oldMapLevel = (IMapLevel)oldSymbol;

                                    }
                                    else if (oldSymbol is IBasicMarkerSymbol)
                                    {
                                        IBasicSymbol newSymbol = new BasicMarkerSymbolClass();
                                        IGraphicAttributes2 newGraphAttr = (IGraphicAttributes2)newSymbol;
                                        IMapLevel newMapLevel = (IMapLevel)newSymbol;
                                        IGraphicAttributes2 oldGraphAtrr = (IGraphicAttributes2)oldSymbol;

                                        IMapLevel oldMapLevel = (IMapLevel)oldSymbol;

                                        for (int O = 0; O < oldGraphAtrr.GraphicAttributeCount; O++)
                                        {
                                            int ID = oldGraphAtrr.ID;
                                            object Val = oldGraphAtrr.get_Value(ID);
                                            string Name = oldGraphAtrr.get_Name(ID);

                                            newGraphAttr.set_Value(ID, Val);
                                        }

                                        newMapLevel.MapLevel = oldMapLevel.MapLevel + 3;

                                        newRepRule.InsertLayer(L, newSymbol);
                                    }
                                    else if (oldSymbol is IBasicFillSymbol)
                                    {
                                    }
                                }
                            }

                            lstNewRules.Add(newRepRule, oldRepName);

                            oldRepRules.Next(out OutIdx, out oldRepRule);

                        }
                        oldRepRules.RemoveAll();
                        foreach (KeyValuePair<IRepresentationRule, string> kvp in lstNewRules)
                        {
                            int RuleId = oldRepRules.Add(kvp.Key);
                            oldRepRules.set_Name(RuleId, "Nieuw" + kvp.Value);
                        }

                        oldRepClass.RepresentationRules = oldRepRules;
                        oldRepRen.RepresentationClass = oldRepClass;
                        pGeoFLayer.Renderer = (IFeatureRenderer)oldRepRen;
                    }
                }
                else
                {
                    pGeoFLayer = null;
                }

Both times I update the folowing objects;
if (pGeoFLayer != null)
                {
                    //This makes the layer properties symbology tab show the correct interface.
                    IUID pUID = new UIDClass();
                    pUID.Value = "{683C994E-A17B-11D1-8816-080009EC732A}";
                    pGeoFLayer.RendererPropertyPageClassID = pUID as UIDClass;
                }
            IMxDocument MxDoc = (IMxDocument)mapDoc;
            MxDoc.UpdateContents();
            mapDoc.ActiveView.ContentsChanged();
            mapDoc.ActiveView.Refresh();
            IContentsView contVieuw = MxDoc.get_ContentsView(0);
            contVieuw.Refresh(null);
0 Kudos
1 Reply
HedwigKupers
New Contributor
ESRI Inc. answered:
"As per the discussion held I would like to share the following information as well the workaround.

Although the programmatically-set symbol levels are being persisted by the GDB, the reason they are not seen in the UI is that the levels set at the renderer will always take precedence. (We actually did this to avoid requiring a schema lock to change them from the UI, to keep the representation renderer in sync as best as possible with the other renderers.)

So, to get around this, programmatically create a new representation renderer, change symbol levels, reassign the representation rules (this requires a schema lock). Apply the updated representation class (with the correct symbol levels) to the new renderer. Then, set the layer to this new renderer and delete the old one. The new renderer should then inherit the programmatically-set symbol layers from within the GDB."
0 Kudos