如何使用 python 中的 win32com.client 将文档另存为 .psb 文件?

How can I save as the document as .psb file using win32com.client in python?

在 photoshop 中使用 python,我无法将活动文档另存为 PSB(大型文档格式)文件

使用 win32com.client,我可以将活动文档保存为 .psd 文件,如下所示:

from win32com.client import Dispatch

psApp = Dispatch("Photoshop.Application")
activeDocument = psApp.Application.ActiveDocument
activeDocument.SaveAs("E:\PSDCopy", PhotoshopSaveOptions, False)

尽管我无论如何都无法强制将其另存为psb。 我在 VBScript 文档中也找不到任何线索,现在甚至连 psb 文件都找不到。

任何帮助将不胜感激。

Adobe 为与 Photoshop 的接口创建了一个糟糕的 API。更糟糕的是,该文档已被弃用,并且不包括 PSB 文件、EXR 文件等更新。

了解如何为此编写代码的一个好方法是使用 Photoshop ActionListener 并自行破解(并不总是有效,但它可以为您提供一些好的线索)。您可以阅读更多相关信息 here

这应该符合您的要求:

import comtypes.client as ct


app = ct.CreateObject('Photoshop.Application')


def save_as_psb(path):
    """ Save the current Document as PSB with maximised compatibility
    turned ON.

    Args:
    path (str): This is the filename of the output PSB
    """

    desc19 = ct.CreateObject("Photoshop.ActionDescriptor")
    desc20 = ct.CreateObject("Photoshop.ActionDescriptor")
    desc20.putBoolean(app.StringIDToTypeID('maximizeCompatibility'), True)

    desc19.putObject(
        app.CharIDToTypeID('As  '), app.CharIDToTypeID('Pht8'), desc20)
    desc19.putPath(app.CharIDToTypeID('In  '), path)
    logging.debug(path)
    desc19.putBoolean(app.CharIDToTypeID('LwCs'), True)
    app.executeAction(app.CharIDToTypeID('save'), desc19, 3)