Skip to main content
richw43882927
Participating Frequently
August 30, 2020
Question

C# Running Actions Command Play Currently Unavailable

  • August 30, 2020
  • 3 replies
  • 3288 views

I have a C# project that I am attempting to Open Photoshop 2019, Run Auto Crop and Straighten on a Canon Raw Image, and save the output image as a TIFF.  I have a Action to perform those tasks.  Running the action in Photoshop works 100% of the time.

 

When attempting to run the action in a Visual Studio 2019 C# windows app.  I am referencing  Photoshop.DLL object library.  When I run "DoAction", I receive a

 

System.Runtime.InteropServices.COMException 

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

 

StackTrace " at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)\r\n at Photoshop._Application.DoAction(String Action, String From) .... etc etc.

 

I some success getting furhter in the process with Photoshop 2020 Type Library but it still wouldnt get through the Actions.

 

Any ideas what is causing this and any solutions? I would like to use 2020 if possible.

This topic has been closed for replies.

3 replies

richw43882927
Participating Frequently
August 31, 2020

So this is odd...
Instead of opening the file as the first step in my Action Set, I opened the file programmatically via C#.

Yes, opening the RAW file loads straight into Photoshop without ACR.

But, I was still getting the error that the DoAction wouldnt work because play wasnt available.

 

Through some tinkering, I was able to add the PhotoshopTypeLibrary as a reference in Photoshop.  I was always getting errors that I couldn't add the TLB for a litany of reasons.

 

When I scrapped Photoshop.DoAction in favor of PhotoshopTypeLibrary.PlayAction , it sort of worked.  I'm going to play with this a bit more.  In the meantime, anyone have any insight into this?

richw43882927
Participating Frequently
September 14, 2020

The issue still isnt solved. IT can run all actions EXCEPT for ImageProcessorPro.  There has to be other people doing this without any issues.

Legend
August 30, 2020
Such an error (in scripts for sure) occurs if either the Action name or the ActionSet name is specified incorrectly.
Check the names, they are case sensitive. There should be no extra or missing spaces.
 

 
richw43882927
Participating Frequently
August 31, 2020

Thanks but I assume you that it is not in the scripts.  This issue is in C# between launching Photoshop and Preparing to run the script. 

 

It's not even getting to that step now.  It's failing before the openning of the cr2 raw image.

JJMack
Community Expert
Community Expert
August 31, 2020

Does Photoshop Plug-in ACR convert the CR2 file raw data and open a new Photoshop document for the cr2 file NO. Photoshop Does not support RAW files Its Plug ACR does.  IS ACR hanging?

JJMack
JJMack
Community Expert
Community Expert
August 30, 2020

Are you referring to Photoshop File>Automate>Crop and Straighten Photos?  If so why are you RAW file not straight? You photographing picture or pages of Text. Why doe you need toe creat a C# application. There  are Photoshop Scripts on the web to batch Crop and Straighten Photos cropAndStraightenBatch.jsx  An Action step Crop and Straighten Photo followed by a simple script step cabs casb and closed all the cripped images. That action can even be batched.

var outputFolder = "~/Desktop/outputFiles";					// Default output files folder
var makeFolder = new Folder(outputFolder);					// make sure the folder 
makeFolder.create();										// exists
app.documents[0].close(SaveOptions.DONOTSAVECHANGES);		// Close the Scan
for (var i=0;i<documents.length;i++) {						// Save the open new image documents
	activeDocument=documents[i];							// Switch Documents
	outputFile = outputFolder + "/" + activeDocument.name;	// Construct full output file path
	SaveAsJPEG( outputFile , 10 );							// Save Jpeg Quality 10 file
}
while (app.documents.length) {
	app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);	// Close the saved new document
}		
//////////////////////////////////////////////
function SaveAsJPEG(saveFile, jpegQuality){
	var doc = activeDocument;
	if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;
	jpgSaveOptions = new JPEGSaveOptions();
	jpgSaveOptions.embedColorProfile = true;
	jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
	jpgSaveOptions.matte = MatteType.NONE;
	jpgSaveOptions.quality = jpegQuality;
	activeDocument.saveAs(File(saveFile+".jpg"), jpgSaveOptions, true,Extension.LOWERCASE);
}
JJMack
richw43882927
Participating Frequently
August 30, 2020

I am looking for a way to run an Action from C#.  If that means I have to run an Action is JSX and use C# to run the JSX file, thats fine too.

 

Re: your screen shot, thats exactly what I'm doing.  However, I've found that doing a batch is too slow. The preference is to do one at a time because as the action is running, the user is placing the next photo on the copy stand.  The action is always done before the user takes the next image so it saves a ton of time at the end of the process waiting on the batch.

 

There is a lot of other things that need to happen before and after the step
to data and "other data" things the image that necessitates a windows
application. Ie. After the image is saved, upload to a Box.com folder for backup.

This is not a case of a graphics designer “using” photoshop to batch images
otherwise all the actions work perfectly.  I wish that it was.

The other part of the application uses Image Processor Pro (Brown) to
perform some resizes and exports.

SuperMerlin
Inspiring
August 30, 2020

Try this...

using System;


namespace Action_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            dynamic app = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));
            runAction(app, "ActionName", "ActionSet");
        }
        static void runAction(dynamic app, string act, string set)
        {
            dynamic d = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.ActionDescriptor"));
            dynamic r = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.ActionReference"));
            r.PutName(app.StringIDToTypeID("action"), act);
            r.PutName(app.StringIDToTypeID("actionSet"), set);
            d.PutReference(app.StringIDToTypeID("null"), r);
            app.ExecuteAction(app.StringIDToTypeID("play"), d, 3);
        }

    }
}