View by status   

Allow an attribute to be added as Dynamic Text

  • 440
    Points

  • It would be quite handy to add an attribute to a map's layout in the form of Dynamic Text.  For example, consider a state transportation map which depicts the maintenance responsibilities of 15 different transportation crews.  Adding the phone number of each crew's supervisor to the legend would greatly enhance the value of the map, but if it is added as a static annotation, you run a very high risk of failing to update the field--phone numbers change frequently.  Using the legend to express the number is feasible, but requires legend manipulation that is a bit tedious. 
    Tags :
     
    Posted by   MLF  to ArcGIS DesktopTransportationProduction Mapping (PLTS) Jan 21, 2011

Share this idea Report Abuse

Comments (18)


Please log in to post a comment.






klisby 
Mar 15, 2013
Chris,
 I have a map book that I'm trying to produce with similar design request. I would like the dynamic text to pull the fire hydrants that are completely within the data driven index grid and display multiple rows. I have a comments column, that is blank, that I would like to populate as well.  I've tried altering the below script but had no luck.


 
This is an excellent and very useful idea.


 
nickvague 
Jan 19, 2012
Hi Chris,

Thanks for that, it is working perfectly now!


 
Chris_Fox 
Jan 18, 2012
try this instead:

>>> import arcpy
>>> mxd = arcpy.mapping.MapDocument("CURRENT")
>>> Address = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","FULLADDRESS")[0]
>>> rows = arcpy.SearchCursor("Land and Property Gazetteer\LPG Properties")
>>> row = rows.next() #This is where I made the change to create a reference to the row object used in the next line to retrieve the value
>>> Address.text = row.getValue("FULLADDRESS")
>>> mxd.save()
 


 
nickvague 
Jan 18, 2012
Hi,

I've been using the codes below as a guide.  I'm trying to get the address of a selected row to appear in the text element, I can get the addresses to appear there using the row.next() but can't seem to get the code to take the data for ma selected row.

Is this possible?  This is my code as it stands so far

>>> import arcpy
>>> mxd = arcpy.mapping.MapDocument("CURRENT")
>>> Address = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","FULLADDRESS")[0]
>>> rows = arcpy.SearchCursor("Land and Property Gazetteer\LPG Properties")
>>> rows = rows.next()
>>> Address.text = row.getValue("FULLADDRESS")
>>> mxd.save()

Thanks for any help
Nick


 
mbd7878 
Dec 13, 2011
raketkarl,
     You also need to make sure the two textboxes have a different Element Name.  If they both have Address as the name then the script will fail. 


 
Chris_Fox 
Dec 6, 2011
The error you are recieving indicates that ListLayoutElements is returning not text elements. I would confirm that you have saved the mxd after adding the text elements. Also change the code to:

addrElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "*")[0]

The code above will just return any text elements in the mxd, regardless of what their name is.


 
raketkarl 
Dec 5, 2011
Hi, 
Looks promising, but I keep getting an error "list index out of range" from this line:
addrElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "Address")[0]

I have added the two textbox to the Test.mxd layer via Insert--> Text, then named added Address in the Element Name. 

What am I missing here? 
Thanks, 
Rasmus


 
timccollins 
Sep 23, 2011
I am looking to do the same sort of thing. Currently I have to create serive layouts for our utility customers. All their information has to be filled in by hand where as all the required infomation is stored in a feature class. By keeping our records up to date keeps the layouts up to date!!


 
mbd7878 
Sep 15, 2011
That is exactly what I need.  Thank you very much for the help.   I am new to scripts, I am finding that I keep over thinking things. 


 
Chris_Fox 
Sep 14, 2011
I believe you could update your code to:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
QuadElem = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","QUAD")[0]
rows = arcpy.SearchCursor("USGS 24k Topo Map Boundaries")
textValue = ""
for row in rows:
      textValue += row.getValue("QUAD_NAME") + ", "
QuadElem.text = textValue


 
mbd7878 
Sep 14, 2011
I could use some help modifying this script. 
I need to do the exact same thing, but I want to populate my text element with mutiple row attributes.
I have a script that selects any 24k quads, from ESRI's Data Maps ArcGIS10 data, that intersects my project limits.

Now the trouble comes when I want to add all the Quads selected QUAD_NAME attribute to my text element.  It only returns one of the results.  Sometimes the project limits will intersect 1 quad or sometimes it will intersect 2 or 3.  How do I get the script to populate my text element with ALL the results of my selection. 

>>> import arcpy
 >>> mxd = arcpy.mapping.MapDocument("CURRENT")
 >>> QuadElem = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","QUAD")[0]
 >>> rows = arcpy.SearchCursor("USGS 24k Topo Map Boundaries")
 >>> row = rows.next()
 >>> QuadElem.text = row.getValue("QUAD_NAME")
 >>> while row:
 ...     print row.QUAD_NAME
 ...     row = rows.next()
 ...


 
Chris_Fox 
Mar 23, 2011
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,     


 
MLF 
Mar 23, 2011
Thanks, Chris!  Do you have a sample or link to a sample of a python script with arcpy.mapping which dynamically updates the text of text elements based on values in non-index layer feature classes?  The "Getting started w/Python" doc is too generalized... Thank you!


 
Chris_Fox 
Mar 17, 2011
@MLF Unfortunately you can't do this through the UI. The issue is that in the index layer, each row in the feature class corresponds to a page so it is very easy to determine which record to pull the value from with data driven pages because you specify the field to use and the page determines which row to grab the value from. With other layers this is likely not the case as there may be multiple values for each page. However, it is possible to build this logic into a python script with arcpy.mapping to dynamically update the text of text elements based on values in other feature classes.


 
MLF 
Mar 16, 2011
Chris, can you do this with an attribute field which is not in the index layer, but is in a different layer? Thank you!


 
duri 
Jan 22, 2011

Yes for Dynamic Text, yes for Dynamic Table! With attributes query, field display and appearance properties. ArcMap completely misses functionality to dynamically publish the desired layer's attributes or the whole attribute table in the Layout View. I don't quite understand, why the it isn't already there.



 
Chris_Fox 
Jan 21, 2011

I am not sure if this is exactly what you are looking for, but you can get functionality similar to this with Data Driven Pages. From this help doc there is a tip near the bottom:

Tip:

With the dyn type="page" you can create dynamic text with any attribute field of the Data Driven Pages index layer. For example, if you have an attribute on the index layer named POPULATION, you can create a dynamic text tag using this field,  <dyn type="page" property="POPULATION"/> to dynamically display the POPULATION values for each page in the layout.

With this functionality if you have an attribute field in an index layer of your data driven pages you can use it as dynamic text for the pages.



 

 

Terms and Conditions   |    Feedback   |   FAQs
Previous MonthNext Month
SunMonTueWedThuFriSat