lohriialo / photoshop-scripting-python

Scripting in Photoshop is used to automate a wide variety of repetitive task or as complex as an entire new feature
486 stars 94 forks source link

General Photoshop error occurred. This functionality may not be available in this version of Photoshop. The command "Play" is not currently available #23

Open sowmyakavali opened 1 year ago

sowmyakavali commented 1 year ago

I have person image with white background , and I have one more image which I am going to use it as new background for person. I am trying to do it in photoshop application with python script.

This is the script I have tried,

import os
import win32com.client

SILENT_CLOSE = 2

# This actually fires up Photoshop if not already running.
ps = win32com.client.Dispatch("Photoshop.Application")
ps.DisplayDialogs = 3            # psDisplayNoDialogs
ps.Preferences.RulerUnits = 1    # psPixels
folder_path = r"C:\Users\MCPL-265\Desktop\ps_connect\TEST\Input"

# Get a list of files in the folder
files = os.listdir(folder_path)
output_folder = r"C:\Users\MCPL-265\Desktop\ps_connect\TEST\Output"

# Create the output folder if it doesn't exist
if not os.path.exists(output_folder):
    os.makedirs(output_folder)

# Loop through the files and open them in Photoshop
for file in files:
    file_path = os.path.join(folder_path, file)
    ps.Open(file_path)

    ps.DoAction("Set1", "Actions")
    output_file = os.path.join(output_folder, file)

    jpgSaveOptions = win32com.client.Dispatch("Photoshop.JPEGSaveOptions" )
    ps.ActiveDocument.SaveAs(output_file, jpgSaveOptions, True, 2)

ps.Quit() # Stops the Photoshop application

NOTE : Here Set1 is the custom action that I have added already in photoshop application. This is the custom action I have loaded.

But It is throwing this error

File "<COMObject Photoshop.Application>", line 2, in DoAction
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe Photoshop', 'General Photoshop error occurred. This functionality may not be available in this version of Photoshop.\n- The command "Play" is not currently available.', None, 0, -2147212704), None)

Please can anyone help me to resolve this issue?

oh-ok commented 1 year ago

Looks like you're referencing the Action Set, not the Action itself here. Changing ps.DoAction("Set1", "Actions") to ps.DoAction("BG", "Set1") will probably make this work.