update all text elememts (not working)

1417
13
11-09-2016 10:41 AM
JaredPilbeam1
Occasional Contributor

Hi,

I ran this script in PythonWin. I have folder(s) full of mxd documents that will require annual updates such as the year (date), which is what I was attempting here. This script ran but there were no changes made to the doc.

So, the original doc is in one folder and I want to change the date then save it in another folder. I've attached a PDF of the map I'm attempting to update. The year (2016) is in the title and signature. In the title, the year is grouped with the rest. That may be a problem?

Is the script wrong? Or is the title not properly represented in the text string?

Thanks in advance.

0 Kudos
13 Replies
DarrenWiens2
MVP Honored Contributor

Yes, I used my script to change the same text in over 200 mxds within a single folder structure (i.e. including subfolders). The only thing I can think of is that my script used mxd.save() and yours uses mxd.saveACopy(...). Not sure if there is some sort of quirk there.

0 Kudos
JaredPilbeam1
Occasional Contributor

Thanks, you've been really helpful. Still getting an error on this, however.

But, your script is just saving into the same folder, correct? I changed your mxd.save() to mxd.saveACopy in order to save to a different folder, as I don't want to copy over the 2016 mxds. That's where I'm confused now. 

So, by including the 1st_District_B.mxd in line 15 it seems to want to copy that particular mxd only. If there was a sort of wildcard operation i can run to avoid these problems that would be great.

For instance, I found this method and adapted it:

Here it got past the first part as you see the print mxdname was carried out. But, only one mxd saved into the new folder and the text wasn't changed either. 

0 Kudos
DarrenWiens2
MVP Honored Contributor

You can see that the code doesn't ever get into the part where it changes the text (you'd also get an error because you've got elm and eml). Is the entire piece of text in the text element '2016' or 'Will County, Illinois ~ 2016'?

If you want the mxd saved each time through the loop, you need to indent it.

If you want to change the name of the saved mxd dynamically, based on the 'mxdname' variable, it would be something like this:

mxd.saveACopy(os.path.join(path_to_your_folder, mxdname))

^ you should use os.path.join to make paths because it handles things like slashes for you.

JaredPilbeam1
Occasional Contributor

@Darren 


So, after your suggestions and getting some more help on this I was able to run it successfully. I indented the mxd.saveACopy and added a if in loop, then printed out what changed.

 

Thanks again for the help.

0 Kudos