Make thumbnail using Python
September 02 2010 |
5 comments
Categories:
Map Data
Hi,
Not sure if this is the right forum, but what code would I use in ArcGIS Desktop 10, using python to automatically make thumbnails of all of my MXD files.
Would this work:
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Clients\2010\client1.mxd")
thumb = mxd.makeThmbnail(mxd)
del mxd
I would be doing a recursive folder search to then list every MXD, so that I could make thumbnails.
Regards...
Mapping Center Answer:
The syntax for creating thumbnails would be: mxd.makeThumbnail (), as you guessed.
ArcGIS 10 has a new embedded Python window where you can test your simple code.
We are not sure if you are asking how to do a recursive search and update thumbnails for all the MXDs at once or if you just want the syntax for creating a single thumbnail. If it is just one thumbnail, then the code above will work.
If it is the thumbnails for all the MXDs in a folder, I am providing you the code below that will loop through the provided folder (first level) and create the thumbnails for each MXD within that folder:
import arcpy, os
# Provide folder path to loop through (first level only)
folderPath = r"D:\MXD"
for filename in os.listdir(folderPath):
fullpath = os.path.join(folderPath, filename)
if os.path.isfile(fullpath):
basename, extension = os.path.splitext(fullpath)
if extension.lower() == ".mxd":
mxd = arcpy.mapping.MapDocument(fullpath)
print "creating thumbnail for " + fullpath
mxd.makeThumbnail ()
mxd.save()
del mxd
You can modify this as needed.
Hope this helps!
Here is my code:
import arcpy, os
# Provide folder path to loop through (first level only)
folderPath = r"C:\TEMP\test"
for filename in os.listdir(folderPath):
fullpath = os.path.join(folderPath, filename)
if os.path.isfile(fullpath):
basename, extension = os.path.splitext(fullpath)
if extension.lower() == ".mxd":
mxdList = folderPath
for mxdPath in mxdList:
mxd = arcpy.mapping.MapDocument(fullpath)
mxd.description = "Python"
mxd.save()
del mxd
def thumbnail():
import arcpy, os
folderPath = raw_input('Enter name of source folder: ')
folderPath = str(folderPath)
thePattern = '.mxd'
for root, dirs, files in os.walk(folderPath):
fileList = [os.path.join(root, fi) for fi in files if fi.endswith(thePattern)]
for item in fileList:
mxd = arcpy.mapping.MapDocument(item)
print 'Creating thumbnail for ' + item
arcpy.AddMessage('Creating thumbnail for ' + item)
mxd.deleteThumbnail()
mxd.makeThumbnail()
mxd.save()
del mxd
response = raw_input('\nDo you want to make more thumbnails
response = response.upper()
if response == 'Y':
thumbnail()
elif response == 'N':
raw_input('\nPress the enter key to quit')
thumbnail()
mxdList = folderPath
for mxdPath in mxdList:
as for filename in os.listdir(folderPath) code line doing looping.
Instead change mxd.makeThumbnail () with mxd.description = "Python", where "Python" would be the description you want to give and it will work.
If you would like to post a comment, please login.