loonghao / photoshop-python-api

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

一个似乎比较罕见的报错 #259

Open sgajs opened 1 year ago

sgajs commented 1 year ago

原本PhotoShopPython-api可以稳定运行(在2023版本的Photoshop里面),但正常运行一段时间后突然弹出请使用正版Photoshop的红色警告,然后后续运行都会报以下错误:

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\baoall\caiwu\python_project\venv\lib\site-packages\comtypes\automation.py", line 792, in Invoke
    self.__com_Invoke(dispid, riid_null, _lcid, _invkind, byref(dp),
_ctypes.COMError: (-2147352567, '发生意外。', (None, None, None, 0, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\baoall\try3.py", line 62, in <module>
    a()
  File "C:\Users\Administrator\Desktop\baoall\try3.py", line 41, in a
    with Session(psd_file_path, action="open") as ps:
  File "C:\Users\Administrator\Desktop\baoall\caiwu\python_project\venv\lib\site-packages\photoshop\session.py", line 341, in __enter__
    self.run_action()
  File "C:\Users\Administrator\Desktop\baoall\caiwu\python_project\venv\lib\site-packages\photoshop\session.py", line 331, in run_action
    _action()
  File "C:\Users\Administrator\Desktop\baoall\caiwu\python_project\venv\lib\site-packages\photoshop\session.py", line 320, in _action_open
    self.active_document = self.app.open(self.path)
  File "C:\Users\Administrator\Desktop\baoall\caiwu\python_project\venv\lib\site-packages\photoshop\api\application.py", line 385, in open
    document = self.app.open(document_file_path, document_type, as_smart_object)
  File "C:\Users\Administrator\Desktop\baoall\caiwu\python_project\venv\lib\site-packages\comtypes\client\dynamic.py", line 121, in __getattr__
    result = self._comobj.Invoke(dispid, _invkind=flags)
  File "C:\Users\Administrator\Desktop\baoall\caiwu\python_project\venv\lib\site-packages\comtypes\automation.py", line 800, in Invoke
    raise COMError(hresult, text, details)
_ctypes.COMError: (-2147352567, '发生意外。', ('非法参数 - 参数 1\n- 缺少必需值', 'Adobe Photoshop', None, 0, -2147220262))

是不是非正版的原因呢?我重新安装了2022版的Photoshop,用2022版时虽然不会跳出非正版的警告,但仍然会报上面“非法参数。。。。缺少必需值”的错误。 我有尝试使用其他电脑使用同样的代码操作非正版2023/2022版的Photoshop,都能正常运行。会不会是之前出现的非正版警告改了些设置使得我的电脑每次运行都会报“非法参数。。。。缺少必需值”这个错误呢?求大佬指明道路。。。

关于运行代码,只是普通地调用PhotoshopPython-API:

import photoshop.api as ps
import pythoncom
from photoshop import Session

def a():
    psd_file_path = r'C:\Users\Administrator\Desktop\psd\276_147\out.psd'
    with Session(psd_file_path, action="open") as ps:
        text_color = ps.SolidColor()
        text_color.rgb.red = 255
        text_color.rgb.green = 255
        text_color.rgb.blue = 255
        text = 'Hello, World!'
        doc = ps.active_document()
        new_doc = doc.artLayers.add()
        new_text_layer = new_doc
        new_text_layer.kind = ps.LayerKind.TextLayer
        new_text_layer.textItem.contents = text
        new_text_layer.textItem.size = 18
        try:
            new_text_layer.textItem.font = "Arial Bold"
        except:
            pass
        new_text_layer.textItem.justification = ps.Justification.Right
        new_text_layer.textItem.color = text_color
        new_text_layer.textItem.position = [268, 137]

if __name__ == '__main__':
    a()
loonghao commented 1 year ago

这个我这边无法复现,我们持续关注一下

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I can't reproduce this here, let's continue to pay attention