2

I'm making an add-in for ArcMap using ArcObjects.

I'm trying to bring an IElement that I've added to the ArcMap.Editor.Map.ActiveGraphicsLayer layer up one level in Z-Order. How do I add my IElement to a IEnumElement so that I can cast the ActiveGraphicsLayer to an IGraphicsContainer and invoke IGraphicsContainer.BringForward(IEnumElement Elements)?

There is no example documentation for situations other than using the existing user selection.

Update: I've tried doing the VB example in C# like so. The element still doesn't come to the top.

using ESRI.ArcGIS.Carto;

namespace XivicToolbar.ArcMapRelated
{
    internal class MapGraphics
    {
        private static IGraphicsContainer Graphics => (IGraphicsContainer)ArcMap.Editor.Map.ActiveGraphicsLayer;

        public void Indicate(IElement element, int zIndex)
        {
            //Add the element 
            Graphics.Reset();
            Graphics.AddElement(element, zIndex);

            //Do z indexing
            for (; zIndex > 0; zIndex--)
            {
                var graphicsSelection = (IGraphicsContainerSelect)Graphics;
                graphicsSelection.UnselectAllElements();
                graphicsSelection.SelectElement(element);
                Graphics.BringForward(graphicsSelection.SelectedElements);
                graphicsSelection.UnselectElement(element);
            }

            //Update the UI
            Refresh();
        }

        private static void Refresh() => ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
    }
}
1
  • There's a VBA sample on GeoNet geonet.esri.com/thread/46865 using the document as an IGraphicsContainer but it should work in your case as ICompositeGraphicsLayer implements IGraphicsContainer but I think there's an error in it, gc.BringForward g.SelectedElements should be gc.BringForward gcs.SelectedElements; the workflow seems to be to iterate through the elements, select the one(s) you want then bring them all forward as IGraphicsContainerSelect.SelectedElements then I would say call IGraphicsContainerSelect.UnselectAllElements to clean up. May 17 '17 at 5:57
2

I've created a work-around by calling the "bring forward" and "send backward" buttons in place of calling Graphics.BringForward(graphicsSelection.SelectedElements). It's pretty nasty but it gets the job done.

 public static void InvokeButton(string id)
 {
     var commandButton = ArcMap.Application.Document.CommandBars.Find(new UID { Value = id });
     commandButton.Execute();
 }

The IDs are:

Send Backward - "{92D490B5-DF9D-11D1-8779-0000F8751720}"

Bring Forward - "{92D490B4-DF9D-11D1-8779-0000F8751720}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.