Saving thumbnails

Saving thumbnails
 1# This example saves thumbnail images of all the items in a specifed folder
 2# and its sub folders. Thumbnails must be enabled from Options > Environment.
 3
 4
 5# Create a local variable for the active database
 6db = impact.active_database
 7
 8# Create a local variable for the output toolbox
 9ot = impact.gui.output_toolbox
10
11
12# Define a sub routine that recurses into folders an saves the thumbnail
13# of each item in each folder
14def export_previews_in_folder(folder):
15
16    # Iterate the child folders
17    for child in folder.children:
18
19        # Iterate the items in the folder
20        for i in range(1, child.item_count  + 1):
21            db_item = child.items.item(i)
22
23            # Create a local variable for the file name of the image
24            file_name = "d:\\new folder\\" + str(db_item.reference) + ".png"
25
26            # Create a local variable to determine if the save was successful
27            save_ok = False
28
29            # go to the next line of code if the SaveThumbnailToFile method fails
30            # for any reason
31
32
33            # if a thumbnail doesn't exist don't create it
34            create_thumbnail = False
35
36            # Save the thumbnail image
37            save_ok = db_item.save_thumbnail_to_file(file_name, ipFileFormat.ffPNG, create_thumbnail)
38
39            # Add an appropriate message to the output toolbox
40            if save_ok:
41                ot.add("Successfully saved thumbnail image '" + str(file_name) + "'")
42            else:
43                ot.add("Failed to save thumbnail image '" + str(file_name) + "'")
44
45        # Recurse into sub folders
46        export_previews_in_folder(child)
47
48
49# Clear the output toolbox
50ot.clear()
51
52# Export all the items in the following folders and subfolders
53# ExportPreviewsInFolder(db.projects)
54# ExportPreviewsInFolder(db.symbols)
55export_previews_in_folder(db.templates)