Skip to main content
stephenw42374084
Inspiring
February 2, 2017
Answered

Executing .jsx Javascript file from .net c#

  • February 2, 2017
  • 1 reply
  • 3841 views

I have a ASP .NET c# website and I want to call a JavaScript file (with extension .jsx)  to create a new image file from Photoshop to display.

No issues or problems with the JavaScript file.

The problem is finding the code in c# to call the JavaScript file from .NET C# (version 4.6) with the correct parameters.

Hoping somebody has solved this before can answer.

Stephen

This topic has been closed for replies.
Correct answer stephenw42374084

Thanks for link to Stack Flow .Net C# code

However this code (adjusted for actual file names ) creates error as follows;

Win 32 Exception was Caught

The specified executable is not a valid application for this OS platform.

So cannot in .NET C# treat .Jsx as Script or Exe - so how can I execute the JavaScript .Jsx file?

Stephen


Finally found a working Solution for .NET C# to use .JavaScript .JSX files.

Add Reference from COM object for Photoshop

Add to top of Code page;

using Photoshop;

Code required is;

            string cFile = HttpContext.Current.Server.MapPath("~/Test Action.jsx");

            Photoshop.ApplicationClass app = new Photoshop.ApplicationClass();

            string[] aArguments= new string[0];  // as no Parameters

            app.DoJavaScriptFile(cFile,aArguments,1) ;  // not sure why it is 1 as final parameter could not find documentation on options.

            app.Quit();

Thanks for contributions.

Hope this solution helps, somebody else.

Stephen

1 reply

Jarda Bereza
Inspiring
February 2, 2017

If your JSX file has

#target Photoshop

on first line in script, then doubleclick on this file can run script in Photoshop (by default).

Doubleclick could be replaced with runing JSX filem from command line. No arguments required.

stephenw42374084
Inspiring
February 2, 2017

Thanks for your reply.

But the code is embedded in a website and the user does not have access to the Desktop, so your proposed solution cannot work

The code required is linked to the action of a button click and is in .NET C# and it requires to execute the JavaScript .Jsx file.

Stephen.

Jarda Bereza
Inspiring
February 2, 2017

If PS and JSX are both server-side then it should work.

You could run "c:\your\path\action.jsx" from C# .NET