skip to Main Content

You can use JavaScripts (Extended Script) out of Photoshop to automate some processes.

There is a way to call JavaScripts for Photoshop with C# with a DoJavaScriptFile() function:

//See the Adobe Photoshop Object Library on the COM
using Photoshop;

static void Main (args string[]) 
{    
//Sample jsx path
var jsxPath = @ "C:\sample.jsx";

//Defines the object type List
var jsxArgs = new List < Object > ();
for (int i = 0; i < args. Length; + + i)
{
    jsxArgs.Add(args [i]);
}

//List containing the arguments to(jsxArgs) a c# ToArray() to convert from //the List into an array.    
app.DoJavaScriptFile(jsxPath, jsxArgs.ToArray(), Photoshop.PsJavaScriptExecutionMode.psNeverShowDebugger);

}

How can I access DoJavaScriptFile() using Delphi code?

The only way I can manipulate Photoshop with my Delphi application uses the RunAction() command (which is not powerful enough for my needs!):

uses ... PhotoShopTypeLibrary_TLB;
var
  Form1: TForm1;
  PS: IPhotoShopApplication;
  DESC: IActionDescriptor;
  Pic: IAutoPSDoc;
  AC: IActionControl;
  xi: Integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
   PS.PlayAction('Name of Photoshop-Action');
end;

Any ideas anybody?

2

Answers


  1. Chosen as BEST ANSWER

    Problem solved:

     procedure TForm1.Testprocedure1Click(Sender: TObject);
     var
         app: OleVariant;
         jsxArgs: Variant;
     begin
         app := CreateOLEObject('Photoshop.Application');  //starts PS
         app.Load(FileListBox1.FileName);   //loads a Picture...
    
         jsxArgs := VarArrayCreate([0,1], varVariant);
         jsxArgs[0] := 3;
         // jsxArgs[1] := ' ';  more Arguments if needed
         app.DoJavaScriptFile(EXEPath + 'jsxflattenLayersOfMe.jsx', jsxArgs, 1);  //runs a JavaScript
    end;
    

  2. Tried with Delphi XE and photoshop CC, when u import its tlb
    enter image description here

    there will be lots of interfaces:

      _Application = dispinterface
        ['{5DE90358-4D0B-4FA1-BA3E-C91BBA863F32}']
    function DoJavaScript(const JavaScriptCode: WideString; Arguments: OleVariant; 
                      ExecutionMode: OleVariant): WideString; dispid 1147828311;
    function DoJavaScriptFile(const JavaScriptFile: WideString; Arguments: OleVariant; 
                          ExecutionMode: OleVariant): WideString; dispid 1147823703;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search