4

I working on mxd with ArcMap 10.3 . The default's legend properties is- Layout - left to right reading (Marked with a red ellipse) :

enter image description here

when it unmarked i get this legend: enter image description here

i want to know if there a way to mark the default box automatic from right to left reading option so the result will be like that (Very important is that all the legend items will be in straight line from left side):

enter image description here

Does anyone know of a way to do this with arcpy?

UPDATE:

I tried MrBubbles answer and the result was:

enter image description here

while i wanted result like that (i made it manually for the example): enter image description here

The answer of MrBubbles didn't help me because it very important that all the words in the legend will be right to left configuration
How can i do it?

3
  • Somehow I think it could be done with arcpy updateitem(use_visible_extent) but i dont know how?
    – newGIS
    Commented Sep 15, 2014 at 9:33
  • If that is possible then I think you would have to author a new legend item that has the Label and/or Description left of the patch using the Style Manager first. This is not something that I have done.
    – PolyGeo
    Commented Sep 15, 2014 at 11:25
  • I wonder if a right to left type python library like this can help you out?
    – dassouki
    Commented Jan 26, 2015 at 13:05

1 Answer 1

4
+25

The trick to doing this is to first create a legend style item either in your user style file or in a custom style file. For the sake of simplicity, I'll show you how to do it using your user style.

  1. In ArcMap, go to Customize > Style Manager You should see a folder in the Style Manager which references the user style file ArcGIS auto-creates to store all your little styling preferences. Click on it so the the right window pane populates with a bunch of empty style folders. ArcGIS Style Manager

You need to create a custom Legend Style item. Specifically, to do what you want to do, you need to create a a Horizontal Legend Style Item.

  1. Right-Click on the Legend Folder in your User Style File and select New > Horizontal... from the context menu. Don't select Horizontal Bar. That's not what you want.

  2. Under the Arrangement tab, select the third radio button from the top, which displays the legend patch all the way to the right. Then press OK and give your legend style item a name. For the sake of simplicity, I named mine 'Justified-Left-Patch-Right' enter image description here

enter image description here

  1. Close the Style Manager.

  2. Next you need to just insert a plain old legend. In ArcMap, select Insert > Legend and just zip through the Legend Wizard. We need the Legend Element in order to update it with your preferred style. If you plan on creating maps dynamically, you would just keep a default legend in the MXD and then update it as needed prior to export. I don't know of a way to just automatically insert a default legend through arcpy.

  3. Once you've got a default legend and your preferred style item in place, we can update the legend with your preferred style through arcpy.

    # Reference the Current MXD
    mxd = arcpy.mapping.MapDocument("CURRENT")
    # Acquire the default legend item manually inserted into the MXD
    legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]
    # Reference your custom style item from your user style
    # Note: "USER_STYLE" is a keyword in the ListStyleItems function which 
    # automatically references the custom style file ArcGIS auto-creates for 
    # your user profile
    styleItem = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items", "Justified-Left-Patch-Right")[0] 
    
  4. At this point, you're ready to update your legend with your preferred style. As you can see, I have the normal default legend in my mxd. MXD prior to updating legend with preferred style

  5. All you need to do now, is iterate through the items in the Legend, and update them with your style item.

    for lyr in legend.listLegendItemLayers():
        legend.updateItem(lyr, styleItem)
    

    enter image description here

You can find more information about updating your legend style through arcpy as well as some additional workflows on with legends in the LegendElement documentation.

Note that while this is the method ESRI provides to update the legend through arcpy, I found it to be fairly unstable. I experienced several hard crashes of ArcMap when doing it. It seemed to occur any time I attempted to update the legend layers after immediately after making a configuration change to my style item in the style manager.

Hope this helps.

6
  • thanks MrBubbles - the items in the legend is turn to left to right but the not vertical.i want to add picture but i don't know how
    – newGIS
    Commented Feb 1, 2015 at 9:30
  • how can i turn all items into straight vertical items?
    – newGIS
    Commented Feb 1, 2015 at 10:46
  • the answer of MrBubbles didn't fit my question
    – newGIS
    Commented Feb 2, 2015 at 11:09
  • MrBubbles how can i turn all items into straight vertical items?
    – newGIS
    Commented Feb 2, 2015 at 14:19
  • Can you give me a picture which represents what you mean? I wouldn't want to give you an answer which doesn't fit your question again.
    – MrBubbles
    Commented Feb 2, 2015 at 16:28

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.