arcpy copy/paste text element within MXD?

3009
2
10-28-2010 08:28 AM
RyanKelley
New Contributor II
My previous post regarding adding a text report of attribute data to an area in an MXD didn't yield any response, and probably isn't possible, so I am taking a new approach.

I have a text element in my MXD called "StateText".

When my cursor grabs the State attribute, it can replace that text string with the State.  What I want to be able to do is, if there is more than one record, copy/paste that string (and rename it before I assign the value) to an x,y location. My python loop can then populate accordingly.  Of course I would need to rename that pasted text string before changing the text, so the text strings remain unique.

rows = arcpy.SearchCursor("lyr_sort")
row = rows.next()

xState = 9.2
y = 9.25

while row:
    stateValue = row.getValue("PROJECT_STATE")
    for elm in MAP.ListLayoutElements(MXD, "TEXT_ELEMENT"):
        if elm.text == "StateText":
            #copy value here to something unique
            elm.text = (str(stateValue) + "\n")
            elm.elementPositionX = xState
            elm.elementPositionY = str(y - 0.25)
    row = rows.next()
0 Kudos
2 Replies
EricAubert
New Contributor II
I don't think you can copy paste a text element since you can't create object with ArcPy.mapping.  However, you can create a pool of text elements outside of yourt page layout (on the margin), and cursor through them and move them where ever you want to on your layout page.  This is how I've been creating dynamic tables using ArcPy.mapping i.e. by using text elements (white background and border line), populate them, for each data driven page.  Hope this helps.
0 Kudos
RyanKelley
New Contributor II
Thanks Eric... I think that will be very useful in some instances. 

Ryan
0 Kudos