Set Preview in Content Browser via Python Script


#1

I’m trying to create a script that would automatically set previews for c4d files in the content browser. For each of them I created a jpg with the same name, but in the documentation I found only a method to get the preview bitmap but none to set one. I would be very grateful to receive any tips on hwo to make this happen. Here’s what I have so far:

Thanks a lot in advance!

import c4d
import os

# Main function
def main():
    libPath = "L:\Library"
    c4dFiles = create_file_list(libPath)
    imgFiles = create_image_list(libPath)
    
    for root, dirs, files in os.walk(libPath):
        for fileName in files:
            filePath = root + os.sep + fileName
            if fileName.endswith((".c4d")):
                  c4dFiles.append(fileName)
            if fileName.endswith((".jpg")):  
                   imgFiles.append(fileName)
            
            for c4dFile in c4dFiles:
                for imgFile in imgFiles:
                    c4dName = c4dFile.split('.')[0]
                    imgName = imgFile.split('.')[0]
                    if (c4dName == imgName):
                        c4d.documents.BaseDocument.GetDocPreviewBitmap(c4dFile)
                        c4d.documents.SaveDocument(c4dFile, filePath, c4d.SAVEDOCUMENTFLAGS_0, c4d.FORMAT_C4DEXPORT)     
                    else:
                       print( "Bitmap file does not exist")
   

def create_file_list(path):
    c4dFiles = []
    return c4dFiles
    
def create_image_list(path):
    imgFiles = []
    return imgFiles    

# Execute main()
if __name__=='__main__':
    main()

#2

This has nothing to do with the Content Browser. The Content Browser only uses the preview image stored in a scene file, so with your GetDocPreviewBitmap approach you were already on the right track.

Over in Plugin Café this has been answered previously, just use the code from the second post: Set Document Preview

Cheers


#3

Thank you!