Use an an ActionMenuItem to Import thumbnails from excel

We've heard from a few of our clients that have thumbnails in their excel sheets and want to upload them into Shotgun.  The problem here is that thumbnails are stored on the web site and need to be uploaded - it's more than just updating the field on the database.  So here's a workaround that adds one small step to accomplish exactly what you want.

Here's what it looks like.  

First import the path to your thumbnails into a text field that you create called ThumbText:



Then, select the ActionMenuItem to upload the thumbnails referenced in your ThumbText field to the thumbnails





  • Select version(s) that have /paths/to/thumbnails in a text field called ThumbText
  • Right-click and select "ThumbText to Thumbnail" action menu item
  • Check out your awesome thumbnails! 




Create a new ActionMenuItem from the Action Menu Items admin page, found in the User Settings menu.
Action Menu Items Admin Page
NOTE: You can also add it to Asset, the code will work for both unaltered.  Also, my protocol handler is called: sgactionmenu.
ActionMenuItem Settings

API Script

Here's the code for the API script:
!/usr/bin/env python
import sys,os
import urllib
import shotgun_api3 as shotgun

SCRIPT_USER = 'my_script'
SCRIPT_KEY = '3th4a5542d38f4a6j3s711fef4e6d24baa0885e4'

# Take the param string arg1=value1&arg2=value2&arg3... and return it in a key:value dictionary
def getParams(a):
        args = a.split("&")
        p = {}
        for arg in args:
                key, value = map(urllib.unquote, arg.split("=", 1))
                p[key] = value
        return p

# Take everything after the protocolhandler as an arg
# Return tuple of the action and a string of all the args
# in the format: arg1=value1&arg2=value2&arg3...
def getActionFullArgs(fp):
        action, fullArgs = fp.split("?", 1)
        action = action.strip("/")
        return action, fullArgs

# This takes a /path/filename from a text field and uploads it as the thumbnail for an entity
# This assumes the field for the thumbnail is in a column called "ThumbText" (sg_thumbtext)
def copyThumbs(sg, params):

        project_id = params['project_id']
        selected_ids = params['selected_ids']
        entity_type = params['entity_type']

        # Loop through the selected IDs
        for id in selected_ids.split(','):
                filters=[['project','is',{'type':'Project','id':int(project_id)}],['id', 'is', int(id)]]
                fields = ['sg_thumbtext', 'image']
                result = sg.find(entity_type, filters, fields)
                sg.upload_thumbnail(entity_type, id, result[0]['sg_thumbtext'])

if __name__ == '__main__':
        # Get the arg string which is 'protocolhandler://action?key1=value1&key2=value2...'
        arg = sys.argv[1]

        # Shotgun!

        protocol, fullPath = arg.split(":", 1)
        action, fullArgs = getActionFullArgs(fullPath)
        params = getParams(fullArgs)

        if action == "thumb":
                copyThumbs(sg, params)



  • 0
    Eloi Bartolome

    Very useful but, how is it supposed to convert thumbnails to its path?

Please sign in to leave a comment.