Original User: Wayne_Whitley
Try out the attached py... hope you now understand what was going awry --- if not I'll try to elaborate a little on the more critical points. I tried not to edit your script much and part of what I did someone else could probably do better but mainly I wanted to leave it mostly intact as you left it in order to 'see' the changes better. Here goes:
- You need 3 text elements already in your map layout. Although you can 'clone' elements at 10.1, I don't think you can create new ones --- at any rate, the 3 elements you should create in your map document should be named:
PRODUCEDBY
PRODUCEDON
PRODUCEDFUNC
You can save names with the elements (create the elements, save and close the map)...a wildcard, "PRODUCED*", is used in the script to 'fetch' the 3 text element objects. 2 of them are preprocessed before entering the export loop; the 1 that changes is of course PRODUCEDFUNC and done in the 'for' loop because (as the name denotes) it is changing as FUNC is in the list generated from your searchcursor on the streets fc.
- Your 1st 'for' loop searched for the street layer; you can exit that loop when the layer is found....you can do that with 'break'. You may want to take this out if you want to print the rest of the layers, but this has nothing to do with the rest of script function, so I chose to 'break out' once the StreetLayer variable was set.
- TOCLayers = ListLayers(mxd, '', dataframe) --- the use of your 'dataframe' variable wasn't mandatory, but since you established it to access and print the extent, it makes sense to 'tighten' the code and use it.
- Your search cursor has a single purpose: to read in unique func vals -- so you can del the cursor and row obj when finished reading (or you can choose to do that at the end of the script along with deleting other objects, it is up to you....I inserted the statement to punctuate the fact it is needed no longer.)
Those are the high notes I guess...simple script, just be careful with your 'for' loops and indention -- your 2 biggest errors I'd say were indenting too much of your code within the 1st 'for' loop and not getting a proper handle on your text elements. Oh yeah, and I didn't see the purpose of 'repositioning' the 1 text element, but if you need it go ahead...
Any further questions let me know -- hope the script works...I tested it, but it can always fail if I forgot to change back to run on your system, etc.
Enjoy,
Wayne
*OOPS:
I see a potential source of error -- see this line which will fail if you intend to fetch the layer from a group layer:
if TOCLayer.longName == 'SONOMA COUNTY STREETS':
This following line will work if you don't need to specify the group layer--
if 'SONOMA COUNTY STREETS' in TOCLayer.longName:
Otherwise, if the 'name' will suffice, simply use--
if TOCLayer.name == 'SONOMA COUNTY STREETS':
Hope that is clear...