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.