Extending Dynamic Text

6760
8
02-01-2011 06:20 PM
MichaelBraun1
New Contributor
Are there any code samples using a python script, or using ArcObjects from within dynamic text?

Is there anyway to extend the information available to dynamic text, or is it limited to the 7 types of dynamic text that are provided with ArcMap (system, document, data frame...)

Thank you,

Mike Braun
Telvent Utilities Group
Tags (2)
0 Kudos
8 Replies
847396730
Occasional Contributor III
If you're using data driven pages, you can easily add Dynamic Text relevant to any of the index layer's attribute fields; just add any old piece of Dynamic Text, right click, and modify the code to reflect the field you want.  There is also a way to use arcpy.mapping to dynamically update text based on non-index layer feature classes; I'll update this post with that info when I have it.
0 Kudos
847396730
Occasional Contributor III
Chris Fox at Esri just kindly posted this example of using python to generate dynamic text outside of the data driven pages/index layer model:

Below is a sample, this assumes i have a map document, two text elements in the layout, a layer named TestLayer with 2 fields "AddressField" and "ZipField".

import arcpy

# get the reference to the map document and the layer named "TestLayer" in the map document
mxd = arcpy.mapping.MapDocument("C:/Temp/Test.mxd")
mapLyr = arcpy.mapping.ListLayers(mxd, "TestLayer")[0]

# get the reference to the text elements in the map document. I have 2 text elements with the name Address and Zip
addrElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "Address")[0]
zipElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "Zip")[0]

# create a cursor and grab the first row in the feature class for the layer specified above
rows = arcpy.SearchCursor(mapLyr.dataSource)
row = rows.next()

# set the text property of the text element equal to the value from the fields named "AddressField" and "ZipField"
addrElem.text = row.getValue("AddressField")     
zipElem.text = row.getValue("ZipField")

# save the map document and delete the reference to the row, cursor and map object
mxd.save()
del mxd, row, rows,
0 Kudos
JakeKrall
Occasional Contributor III
Is there some code to grab "Bookmarks" to use as dynamic text?  I have several bookmarks and would like to have the text change for each bookmark I choose to provide the title for the map.
Thanks,
Jake
847396730
Occasional Contributor III
I don't know of a way to do that, but if your bookmark names are related somehow to attributes in your data, you could fashion dynamic text out of that.
0 Kudos
NathanEide
New Contributor
Chris Fox at Esri just kindly posted this example of using python to generate dynamic text outside of the data driven pages/index layer model:

Below is a sample, this assumes i have a map document, two text elements in the layout, a layer named TestLayer with 2 fields "AddressField" and "ZipField".

import arcpy

# get the reference to the map document and the layer named "TestLayer" in the map document
mxd = arcpy.mapping.MapDocument("C:/Temp/Test.mxd")
mapLyr = arcpy.mapping.ListLayers(mxd, "TestLayer")[0]

# get the reference to the text elements in the map document. I have 2 text elements with the name Address and Zip
addrElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "Address")[0]
zipElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "Zip")[0]

# create a cursor and grab the first row in the feature class for the layer specified above
rows = arcpy.SearchCursor(mapLyr.dataSource)
row = rows.next()

# set the text property of the text element equal to the value from the fields named "AddressField" and "ZipField"
addrElem.text = row.getValue("AddressField")     
zipElem.text = row.getValue("ZipField")

# save the map document and delete the reference to the row, cursor and map object
mxd.save()
del mxd, row, rows,


This is exactly (at least I think) what I want to do.  Problem is, I'm a VBA programmer and I'm really struggling to switch over to Python.  I've tried pasting the code into the Python Windo in ArcMap.  I've change all the variables.  I can't seem to get the script to run like I think it should.  Nothing happens and I get and error message ('exceptions.IndexError')  Any tips for a budding Python programmer?
0 Kudos
847396730
Occasional Contributor III
Hello! I suggest you paste the script and your question on Arc's Python forum: http://forums.arcgis.com/forums/117-Python

You'll reach a more appropriate pool than with just this one thread.  Good luck; I'm looking forward to the answer!
0 Kudos
joesather
New Contributor II
I have found that it is very easy to insert any Index layer data to the Layout Using the Insert  - Dynamic Text Tool.  Simply understanding that "Page" is synonymous with your index Layer will serve you well. 

I have a County Name in my index Layer field that I want to add to my layout.
I simply Insert - Dynamic Text - Data Driven Page Name.  When looking at the properties of this tag it should read as follows:

<dyn type="page" property="name"/>

I want that text to actually display the County Name that is associated with that page, I have a field in my index layer called "County".  I simply edit the string to read as follows:

<dyn type="page" property="County"/>

I am used to DS Mapbook, and I am trying to recreate the same functionality in Data Driven Pages.  I guess it took me a while to realize that the "Page" dynamic text type was actually tied to my index layer.  I can't find where the ArcGIS Desktop Help indicates that "Page" text is in any way related to the index Layer, but the results speak for themselves.  Apparently it is so simple that it needs to explanation.
0 Kudos
LouiePadilla
New Contributor

Is there a way to use python in a dynamic text where it looks for the dynamic text by attribute and depending on that value, you place and if else. If attribute = 0 then "No", else "Yes"?

0 Kudos