0

I am facing an error when I try to open Photoshop using Python. I have made an application to take user data using Tkinter and then it appends the data in a CSV file. I also want it to generate an image with that data using the template I have created on Photoshop. But for some reason, my program opens Photoshop correctly but also generates an error message:

Traceback (most recent call last):
 File "d:\Coding\Python Scripts\Dr Nikhil Prescription App\PS_test.py", line 3, in <module>
   psApp.Open("Presc_Template.psd")
 File "<COMObject Photoshop.Application>", line 2, in Open
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe Photoshop', 'Illegal argument - argument 
1\n- Expected a reference to an existing File/Folder', None, 0, -2147220262), None)

Which is bad for me since I will be turning this into a software. Here is the code...

main.py:

import win32com.client, os
psApp = win32com.client.Dispatch("Photoshop.Application")
psApp.Open("D:\Coding\Python Scripts\Dr Nikhil Prescription App\Prescription Generator\Presc_Template.psd")
doc = psApp.Application.ActiveDocument
layer_facts = doc.ArtLayers["Layer"] #Opening the specific layer
text_of_layer = layer_facts.TextItem
text_of_layer.contents = "This is a test." #Making changes to the text in the layer

What should I do to overcome this problem so that I am able to overcome this error that keeps popping up every time I try to open up Photoshop using Python? My purpose is to automate the task of adding data from a CSV file into a Photoshop Template and then render it each time the user wants to do it.

halfer
  • 19,824
  • 17
  • 99
  • 186
Deven Jain
  • 27
  • 1
  • 8
  • 1
    You may be able to use the open-source [GNU GIMP](https://www.gimp.org/) which is designed with exactly this workflow of input->scripting->resultant in mind – ti7 May 19 '21 at 17:08
  • Thank you for replying but Problem resolved! Please [click here](https://stackoverflow.com/q/67607868/15773448) – Deven Jain May 19 '21 at 17:12
  • https://stackoverflow.com/q/67632289/15773448 – Deven Jain May 21 '21 at 07:09

0 Answers0