Select to view content in your preferred language

Text Element Questions

4062
34
Jump to solution
08-14-2013 11:36 AM
GeoffOlson
Regular Contributor
So I've got my text element function working in layout view, but it leaves me with two questions.  Can multiple rows be concatenated into the row.getValue or can it only find single fields?  Also, is it possible to return all feature records?

Here is the script I'm using to get the first result to fill the text box:

import arcpy  mxd = arcpy.mapping.MapDocument("Current") mapLyr = arcpy.mapping.ListLayers(mxd, "Detail_2013")[0]  concatElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "concat")[0]  rows = arcpy.SearchCursor(mapLyr.dataSource) row = rows.next()  typeElem.text = row.getValue("CONCAT")  mxd.save() del mxd, row, rows,


Any suggestions a much appreciated.
Tags (2)
0 Kudos
34 Replies
T__WayneWhitley
Honored Contributor
ah, well you want to make your columns sensitive to DDP...I don't recall you saying that in the beginning.

Anyway, I think you are going to need access to the pageRow property, see this:

http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000030000000


...then link your search cursor query to those rows dependent on the current page, recycling your searchcursor, in turn recycling your page columns.  I think that'll work.  There are code samples at that webhelp link.

Hope that helps,
Wayne
0 Kudos
GeoffOlson
Regular Contributor
Yeah, I knew I was using DDP from the beginning, but I expected the definition and page query to limit the results to the queried features.  I'll look at the link and see what I can do.  Thanks for all the help so far.
0 Kudos
GeoffOlson
Regular Contributor
I think that's beyond what I can figure our right now.  I'm happy with what I've accomplished.  I might use the split layer by attributes and create separate shapefiles for each map page, then the script can be run on each layer.  I would just need to change the layer name each for each page, but it would be a workaround.

Thanks for all your help, have a great weekend.
0 Kudos
MathewCoyle
Honored Contributor
Your issue with the search cursor not being limited by the definition query on the layer is that you are not referencing the layer, you are referencing the data source feature class.

This
rows = arcpy.SearchCursor(mapLyr.dataSource, "PageID = \'Intersec\'")

Should just be this
rows = arcpy.SearchCursor(mapLyr, "PageID = \'Intersec\'")
0 Kudos
GeoffOlson
Regular Contributor
Wow, that is really useful information.  Thanks mzcoyle!  In the line is PageID supposed to be the field being searched and is Intersec supposed to be the value of that field in the row in a wildcard format?
0 Kudos
MathewCoyle
Honored Contributor
Sorry I had misunderstood, your pageID variable is the value of the field, I had thought it was the field name. So yes you are right. PageID is supposed to be the field being searched and Intersec supposed to be the value of that field in the row. As your input you assign pageNum as the variable, this is supposed to be the page name but maybe you just have the page name set as a number?

Based on how I understand your code, I think this is what you want to be doing.

import arcpy
pageNum = arcpy.GetParameterAsText(0)
ddp = mxd.dataDrivenPages
arcpy.AddMessage(pageNum)
pageID = ddp.getPageIDFromName(str(pageNum))
ddp.currentPageID = pageID

rows = arcpy.SearchCursor(mapLyr, "{0} = {1}".format(ddp.pageNameField.name, pageNum))


That is assuming you are passing the page name as your parameter (pageNum). That is also assuming you are accessing the ddp layer in your cursor, if you are trying to access some other layer that would require some more creative solutions.
0 Kudos
GeoffOlson
Regular Contributor
That has me thinking of two questions.  Does the layer being searched have to be the index layer?  I imagine that it doesn't.  Also, is pageName only a number?  I haven't seen anywhere that getPageIDFromName actually returns the string of the field attribute but returns a number based on the sort order of the DDP.
0 Kudos
MathewCoyle
Honored Contributor
That has me thinking of two questions.  Does the layer being searched have to be the index layer?  I imagine that it doesn't.  Also, is pageName only a number?  I haven't seen anywhere that getPageIDFromName actually returns the string of the field attribute but returns a number based on the sort order of the DDP.


getPageIDFromName returns the numeric PageID with the string of the field attribute as the input. And yes, the layer being searched must be the ddp index layer. To search another layer, as I said, you will have to get creative with how they are related to each other; either spatially or tabularly.
0 Kudos
GeoffOlson
Regular Contributor
Then I guess this just got more complicated.  So I'll explain my map book.  It's a collection of intersections with crash data.  Each page is a tile of an intersection and within each tile are the point features.  What I'm trying to label in the layout is the description of each point.  Originally I was expecting the definition queries of the point layer would control which points were being labelled.  I didn't know what the python script would disregard that control.  My basic script works great for a single page if all the features are in the page extent.  As you can tell, I still have  lot to learn about Python and I keep getting into more advanced programming of this script.I tried using the ESRI example from  South Kingston, RI with their plat map book and it's really helped me learn a lot of getting a script set up.  I think for now I will work with what I have to limit the amount of time I'm spending on this.  Once I work through my "Python Scripting for ArcGIS" book I'll look at this again and hopefully have a better understanding of how to use more of the tools and functions of arcpy.  I won't call this thread dead because this is a tool I would like to have working for future maps, but for now I'll have to work with what I got.  Thank you for all your help, I've really learned a lot and feel like I've gotten a good start into Python with ArcGIS.
0 Kudos
RhettZufelt
MVP Notable Contributor
Geoff,


Originally I was expecting the definition queries of the point layer would control which points were being labelled. I didn't know what the python script would disregard that control.


You can set the same definition query in the SQLclause portion of the labelClass if you only want it to label features that are valid in the layer definition query.

http://resources.arcgis.com/en/help/main/10.1/index.html#/LabelClass/00s30000002t000000/

R_
0 Kudos