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

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

Open sowmyakavali opened this issue 1 year ago • 1 comments

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?

sowmyakavali avatar Jun 07 '23 11:06 sowmyakavali

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.

oh-ok avatar Jul 09 '23 14:07 oh-ok