I have written a very simple tool that builds thumbnails for every map document in a folder : root_fld
stands for root folder and rec
tells if search must be recursive.
import arcpy
import os
import fnmatch
import glob
# getting list of mxds
if rec:
# going recursive
matches = []
for root, dirnames, filenames in os.walk(root_fld):
for filename in fnmatch.filter(filenames, '*.mxd'):
matches.append(os.path.join(root, filename))
else:
# going flat
matches = glob.glob(os.path.join(root_fld, '*.mxd'))
# create thmb
for m in matches:
mxd = arcpy.mapping.MapDocument(m)
mxd.makeThumbnail()
mxd.save()
Works fine but some thumbnails are a pain to create and i'd like my script to filter and ignore mxds that already have a thumbnail :
...
if not mxd.hasThumbnail():
mxd.makeThumbnail()
mxd.save()
According to MapDocument class documentation (http://resources.arcgis.com/fr/help/main/10.1/index.html#//00s30000000n000000), this property doesn't seem to exist. But maybe there's a workaround ?
2 Answers 2
As you noted there is no property to test for a thumbnail. In VBA you can test for the existence of a thumbnail with this simple bit of code:
Public Sub test()
Dim pMapDocument As IMapDocument
Set pMapDocument = ThisDocument
Dim pic As stdole.IPicture
On Error GoTo eH
Set pic = pMapDocument.Thumbnail
Exit Sub
eH:
MsgBox "Map Document has no thumbnail!", vbExclamation
End Sub
Although I have never done it you can use ArcObjects from within python. There is rather useful pdf that talks you through the process of using a module called comtypes
. This is probably the only solution for you.
-
Comtypes seems to be the way to go. I'll give it a try and post a snippet as soon as I get a success.outforawhile– outforawhile2014年03月18日 17:11:42 +00:00Commented Mar 18, 2014 at 17:11
From what I can tell you can only delete and make the thumbnail. You could just have it delete and then remake every single thumbnail, but you've probably already thought of that.
But as I understand, some thumbnails aren't being created correctly with Python, so you created them manually and want them to be skipped.
-
It's not exactly that Python can't create correct thumbnails: the problem is that in some cases (especially data driven pages mxds) it takes forever to generate thumbnails. I want to launch my script as a cron task every night to generate thumbnails for mxds that don't have one already (those recently created) but I want my script to ignore those who already have one.outforawhile– outforawhile2014年03月18日 17:15:42 +00:00Commented Mar 18, 2014 at 17:15