loonghao / photoshop-python-api

Python API for Photoshop.
https://loonghao.github.io/photoshop-python-api/
MIT License
598 stars 68 forks source link

export_layers_use_export_options_saveforweb donesn't work #347

Closed horiebin closed 1 month ago

horiebin commented 1 month ago

export_layers_use_export_options_saveforweb donesn't workA clear and concise description of what the bug is. I try the example given, it comes out a error

Traceback (most recent call last): File "C:\Users\dxx1\AppData\Local\Programs\Python\Python36\lib\site-packages\comtypes\client\lazybind.py", line 123, in __bind return self._tdesc[(name, invkind)] KeyError: ('exportDocument', 3)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): doc.exportDocument(image_path, exportAs=2, options=options) File "C:\Users\dxx1\AppData\Local\Programs\Python\Python36\lib\site-packages\photoshop\api_document.py", line 330, in exportDocument return self.app.exportDocument(file_path, exportAs, options) File "C:\Users\dxx1\AppData\Local\Programs\Python\Python36\lib\site-packages\comtypes\client\lazybind.py", line 161, in getattr descr = self.bind(name, DISPATCH_METHOD | DISPATCH_PROPERTYGET) File "C:\Users\dxx1\AppData\Local\Programs\Python\Python36\lib\site-packages\comtypes\client\lazybind.py", line 126, in bind descr = self._tcomp.Bind(name, invkind)[1] File "C:\Users\dxx1\AppData\Local\Programs\Python\Python36\lib\site-packages\comtypes\typeinfo.py", line 366, in Bind raise NameError("Name %s not found" % name)

the code is like this: """Export every layer as a .png file use ExportOptionsSaveForWeb."""

Import built-in modules

import os

Import third-party modules

import examples._psd_files as psd # Import from examples.

Import local modules

from photoshop import Session

PSD_FILE = psd.get_psd_files()

def hide_all_layers(layers): for layer in layers: layer.visible = False

psd_file = PSD_FILE["export_layers_as_png.psd"] with Session(psd_file, action="open") as ps: doc = ps.active_document options = ps.ExportOptionsSaveForWeb() layers = doc.artLayers for layer in layers: hide_all_layers(layers) layer.visible = True layer_path = os.path.join(doc.path, layer.name) print(layer_path) if not os.path.exists(layer_path): os.makedirs(layer_path) image_path = os.path.join(layer_path, f"{layer.name}.png") print(image_path) doc.exportDocument(image_path, exportAs=ps.ExportType.SaveForWeb, options=options) ps.alert("Task done!") ps.echo(doc.activeLayer)

horiebin commented 1 month ago

my python version is 3.6 after I update to 3.12, it works