4

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 ?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Mar 18, 2014 at 8:24

2 Answers 2

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Mar 18, 2014 at 15:00
1
  • 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. Commented Mar 18, 2014 at 17:11
0

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Mar 18, 2014 at 13:55
1
  • 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. Commented Mar 18, 2014 at 17:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.