Solved! Go to Solution.
df.extent = parcels.getSelectedExtent(True)
Just a hunch, but I'd try taking out the line:df.extent = parcels.getSelectedExtent(True)
Since you do a zoomtoselectedfeatures just above it, it is unnecessary unless there are selected features in other layers in the saved mxd. And if there are, I'd unselect them and save it that way. My hunch is that you've run into a bug (NIM082523) that causes a crash when you get extents from layers in map docs that have been created or addressed with GP tools. I may be wrong, but it looks suspiciously like the issue in this post:
http://forums.arcgis.com/threads/61570-Layer.getExent()-Crashes-Arcmap
Maybe not, but it's worth a try. I don't see anything else glaringly wrong.
good luck,
Mike
After a 2nd look, I see you are deleting the reference to mxd in the printpdf function. This is not good, take that out. That will probably fix your problem, but I'd recommend loosing the globals altogether. They come back to bite you often, just like this. Outer-scope constants are fine, but any name that's going to have the object it points to change, or is pointing to a mutable object, is better passed to functions as an argument. If you had done that, then your del statement would be no problem.
Anyway, take out the del statement, and you should be good to go.
Mike