3

How can I have a dynamic title of the map, which changes depending on the layer chosen? Is this doable? It would save a lot of time and iterations since I should be producing several maps.

To illustrate, I want the title to get the name of the first layer ticked if several layers are ticked. Any hint will be useful.

3
  • What version of ArcMap? There is a similar functionality to what you are looking for that is called Dynamic Text (Found under Insert->Dynamic Text Menu), but it does not look like an actual Layer Name is an option to pick. You could definitely do this with some custom Python programming though.
    – MLowry
    Commented Jul 8, 2014 at 16:12
  • "first layer ticked", does this mean top most ticked layer in the layers table of contents?
    – artwork21
    Commented Jul 8, 2014 at 17:28
  • ArcMap 10.2 Exactly, the top most ticked layer in the layers table of contents.
    – dimitris
    Commented Jul 9, 2014 at 7:08

1 Answer 1

6

Not fully dynamic, but in general this python code snippet will update a text element with the topmost layer name that is turned on in the defined dataframe:

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] # default Layers dataframe
for lyr in arcpy.mapping.ListLayers(mxd, "*", df):
     if lyr.visible == True:
          for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
               if elm.text == 'Text': # whatever your text element is named here
                    elm.text = lyr.name
                    break
6
  • I run it but no title appears in the map. Any idea what it could be?
    – dimitris
    Commented Jul 9, 2014 at 7:52
  • For this example, you have to create a text element in the layout which text = 'Text' (default). This snippet does not create a text/title.
    – artwork21
    Commented Jul 9, 2014 at 11:57
  • OK. I add a text element and I let the default text 'Text'. I run the tool and nothing happens. May be I am missing a step or? Your input is very much appreciated.
    – dimitris
    Commented Jul 9, 2014 at 14:56
  • Make sure your text element in the layout does not have single quotes around it.
    – artwork21
    Commented Jul 9, 2014 at 16:28
  • artwork21, could you explain further because neither that is working. I go to Insert-->Text. Then I run the script which is saved in a toolbox. It runs but nothing changes. The Text remains Text.
    – dimitris
    Commented Jul 10, 2014 at 10:30

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.