0

I have many projects (mxd) and I´d like to convert ANY "live" elements like legends, scale bars, scale texts etc. into graphic automatically using arcpy. Is there a way? In questions and answers I could not find anything which would help me with that.

These elements have their names, e.g. Legend, Scale Bar and so on. If I wouldn´t want to convert all of them, how do I select which element to convert? Because there can be more elements with the same name, for example 3 legends with "Legend" as the name of the element. Could anybody help?

ArcGIS for Desktop 10.1 Basic, Python 2.7

1
  • 1
    As far as I know you cant convert layout elements to graphics with arcpy. If you want to select specific elements you can use the ListLayoutElements() function with a wildcard like 'legend' to return a list of all the legend elements. Check this linkout for some more info on what you can do with layout elements and some best practices for naming elements. Commented Dec 11, 2014 at 19:01

1 Answer 1

1

You can use arcobjects for this by grabbing the element envelope and converting it to graphic:

This example shows how to do it for legend element.

Converting Legend to IGraphicsComposite in C#

// Convert legend to graphics
IPageLayout pageLayout = mxDoc.PageLayout;
IActiveView activeView = (IActiveView) pageLayout;
IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;
graphicsContainer.Reset();
IElement element = graphicsContainer.Next();
while (element != null)
{
    if (element is IMapSurroundFrame)
    {
        IMapSurround mapSurround = ((IMapSurroundFrame)element).MapSurround;
        if (mapSurround is ILegend)
        {
             ILegend legend = (ILegend)mapSurround;
             IGraphicsComposite graphComp = (IGraphicsComposite)legend;
             IEnumElement enumElem = graphComp.get_Graphics(activeView.ScreenDisplay, 
                                          element.Geometry.Envelope);
             ...
        }

   }
   element = graphicsContainer.Next();
}
1
  • Well, I´m not a C# programmer and as Chris R wrote there is no such solution with Python. As I cannot execute this code in C#, should I mark this answer as "accepted" even before trying? Thanks for your reply
    – jonlew
    Commented Dec 16, 2014 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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