photoshop-python-api icon indicating copy to clipboard operation
photoshop-python-api copied to clipboard

error when working with photoshop since version 23.5

Open vladislavmass opened this issue 3 years ago • 12 comments
trafficstars

Describe the bug An error occurs when opening a session or when trying to call the add method on a document.

To Reproduce Steps to reproduce the behavior:

  1. Run "hello world" example
  2. See error

StackTrace (env) PS D:\projects\python\test> python ony.py Traceback (most recent call last): File "D:\projects\python\test\ony.py", line 3, in doc = app.documents.add() File "D:\projects\python\test\env\lib\site-packages\photoshop\api_documents.py", line 51, in add self.app.add( TypeError: '_Dispatch' object is not callable StackTrace with Session (env) PS D:\projects\python\test> python ony.py Traceback (most recent call last): File "D:\projects\python\test\env\lib\site-packages\comtypes\automation.py", line 791, 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 "D:\projects\python\test\ony.py", line 7, in doc.selection.rotate(90, ps.AnchorPosition.MiddleCenter) File "D:\projects\python\test\env\lib\site-packages\photoshop\api_selection.py", line 119, in rotate self.app.rotate(angle, anchor) File "D:\projects\python\test\env\lib\site-packages\comtypes\client\dynamic.py", line 121, in getattr result = self._comobj.Invoke(dispid, _invkind=flags) File "D:\projects\python\test\env\lib\site-packages\comtypes\automation.py", line 799, in Invoke raise COMError(hresult, text, details) _ctypes.COMError: (-2147352567, 'Ошибка.', ('Неверный аргумент - аргумент 1\n- Требуемое значение пропущено', 'Adobe Photoshop', None, 0, -2147220262))

Desktop (please complete the following information):

  • OS: Windows11 22H2
  • Photoshop Version: 23.5.2 and 24
  • Python Version: 3.10.8

vladislavmass avatar Oct 23 '22 20:10 vladislavmass

Unfortunately, my system has not been updated to windows11 for a while, so I can't test it for you. theoretically compatible.

loonghao avatar Nov 05 '22 12:11 loonghao

@loonghao Checked on Windows 10 and the problem persists. The problem occurs when switching from Photoshop version 23.4 to 23.5 and higher

vladislavmass avatar Nov 06 '22 07:11 vladislavmass

@vladislavmass I have tested use python-3.10.8 in Photoshop 2022(23.5.2) , that is working. image

loonghao avatar Nov 06 '22 16:11 loonghao

@loonghao 24 version also works for you without problems?

vladislavmass avatar Nov 06 '22 18:11 vladislavmass

@loonghao 24 version also works for you without problems?

Since 24 version doesn't support my current system version (win10), I can't test

loonghao avatar Nov 07 '22 02:11 loonghao

@vladislavmass This is kind of a notorious problem unfortunately, its not the Photoshop version. In my experience updating Photoshop or installing a newer version atop an older version can just break the ability to communicate with it using the API/COM/RCP whatever system. If you update Photoshop and find that it doesn't work, my advice would be to completely uninstall Photoshop from your system and then install the latest from fresh. It should work after that (sometimes I've had to do this twice). Also, another caution: The API ESPECIALLY does not like having two versions of Photoshop installed, never install two versions of Photoshop, it pretty much breaks scripting altogether (javascript and python)

Investigamer avatar Nov 07 '22 21:11 Investigamer

@loonghao I believe Photoshop 24 does support Win10 as long as you've received the latest windows update/service pack, or am I wrong? That would be crazy if Adobe requires an update to Win11 altogether..

Investigamer avatar Nov 07 '22 21:11 Investigamer

@MrTeferi reinstalling helped with version 23. This is not the case with version 24. I reinstalled it 10 times already and it doesn't work. At the same time, the connection with Photoshop is clearly established. And then there are errors.

vladislavmass avatar Nov 08 '22 10:11 vladislavmass

@loonghao If you believe the official documentation of Photoshop, then it supports Windows 10 with update 21h1

vladislavmass avatar Nov 08 '22 10:11 vladislavmass

Thật không may, đây là một vấn đề khét tiếng, nó không phải là phiên bản Photoshop. Theo kinh nghiệm của tôi, cập nhật Photoshop hoặc cài đặt phiên bản mới hơn trên phiên bản cũ hơn chỉ có thể phá vỡ khả năng giao tiếp với nó bằng cách sử dụng API / COM / RCP bất kỳ hệ thống nào. Nếu bạn cập nhật Photoshop và thấy rằng nó không hoạt động, lời khuyên của tôi là gỡ cài đặt hoàn toàn Photoshop khỏi hệ thống của bạn và sau đó cài đặt phiên bản mới nhất từ mới. Nó sẽ hoạt động sau đó (đôi khi tôi đã phải làm điều này hai lần). Ngoài ra, một cảnh báo khác: API ĐẶC BIỆT không thích cài đặt hai phiên bản Photoshop, không bao giờ cài đặt hai phiên bản Photoshop, nó phá vỡ hoàn toàn kịch bản (javascript và python)

I also have the same problem when running from 2 photoshop applications, I don't know how to specify the photoshop version or copy the reg of that photoshop version

nqthaivl avatar Jul 30 '24 15:07 nqthaivl

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


Unfortunately, this is a notorious problem, it's not specific to the Photoshop version. In my experience, updating Photoshop or installing a newer version on top of an older version can just break the ability to communicate with it using API/COM/RCP whatever the system is. If you update Photoshop and find that it doesn't work, my advice is to completely uninstall Photoshop from your system and then install the latest version from fresh. It should work after that (sometimes I've had to do this twice). Also, another warning: API SPECIFICALLY does not like installing two versions of Photoshop, never install two versions of Photoshop, it completely breaks the script (javascript and python)

I also have the same problem when running from 2 photoshop applications, I don't know how to specify the photoshop version or copy the reg of that photoshop version

Issues-translate-bot avatar Jul 30 '24 15:07 Issues-translate-bot

@vladislavmass

@MrTeferi reinstalling helped with version 23. This is not the case with version 24. I reinstalled it 10 times already and it doesn't work. At the same time, the connection with Photoshop is clearly established. And then there are errors.

I know this is an old comment, but if you still have this issue, sometimes it isn't enough to uninstall Photoshop and reinstall. Sometimes registry information can persist through installs (which is what causes all of these issues, mismatch in registry data that is used to communicate with the correct Photoshop application and components). After uninstalling Photoshop, in registry go to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Adobe and delete the "Photoshop" folder. Then in registry go to Computer\HKEY_CURRENT_USER\Software\Adobe and delete "Photoshop" there as well. Then in registry go to Computer\HKEY_CLASSES_ROOT and scroll down until you get to the entries starting with P, look for anything with "Photoshop.", each of these entries governs different components of Photoshop, things like "Photoshop.ActionDescriptor", "Photoshop.Application", etc. Delete any of these starting with "Photoshop." After that, reinstalling Photoshop should add new registry entries which only match the new Photoshop version, and the API should function fine.

@nqthaivl

I also have the same problem when running from 2 photoshop applications, I don't know how to specify the photoshop version or copy the reg of that photoshop version

When using the API, you can pass a version when creating the Photoshop application object:

from photoshop.api import Application

app = Application('2024')

I cannot remember if there is a way to specify the Beta version of current year over the non-Beta version of current year Photoshop, I believe it is by supplying the actual numeric value of the version in question but I'll have to refresh on that. For most people, simply opening Photoshop first before you use the API will ensure the API uses the one that is already running, but again this depends on some system level stuff that might be different from person to person, ymmv. I've designed a lot of ways around this myself in my app, feel free to check my implementation. You can find the components I built on top of the Photoshop application object in src/utils/adobe.py.

One thing that is particularly important when it comes to specifying which version of Photoshop to use, is that the very first Photoshop object that is initialized in your app MUST specify the version. Once the version has been specified, any Photoshop related object you use after that will automatically pickup an os.environ variable that is established when the first object is initialized. That environ variable ensures that any subequent COM calls to establish a Photoshop object will ask for the version you specified. If you don't specify the version in the very first object that is initialized, then specifying a version later may cause COM system errors since the different COM objects will be in conflict with one another.

Investigamer avatar Jul 30 '24 17:07 Investigamer