Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
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 Jul 8 at 16:12
    
"first layer ticked", does this mean top most ticked layer in the layers table of contents? –  artwork21 Jul 8 at 17:28
    
ArcMap 10.2 Exactly, the top most ticked layer in the layers table of contents. –  dimitris Jul 9 at 7:08
add comment

1 Answer 1

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
share|improve this answer
    
I run it but no title appears in the map. Any idea what it could be? –  dimitris Jul 9 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 Jul 9 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 Jul 9 at 14:56
    
Make sure your text element in the layout does not have single quotes around it. –  artwork21 Jul 9 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 Jul 10 at 10:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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