Copy link to clipboard
Copied
Have tried over 25 syntax variations of passing a series of 3 Parameters to a JavaScript JSX script file for Photoshop.
However they all come through as 'undefined' or illegal and they stop the code.
If anybody has experience of using Photoshop with .NET C#, I would really appreciate a solution to passing the correct format of Arguments in the command DoJavaScriptFile() and them picking them up in my .JSX file as Parameters.
Thanks for looking.
Stephen
No, the variables would have to local, stored in Photoshop, or a local file.
You could use:
To set up as many variables as you like in Photoshop before calling the script.
string arg1 = "1st Parameter";
string Code = "$.setenv('arg1', '" + arg1 + "');";
app.DoJavaScript(Code, null, null);
example jsx
If($.getenv("arg1") == null){
alert("no variable in arg1");
}else{
alert($.getenv("arg1"));
}
Copy link to clipboard
Copied
You don't. You have the script read your parameters from a file or from stored variables. I.E using $.setenv(); / $.getenv();
Copy link to clipboard
Copied
Thank you for your reply.
Sorry I don't understand. I'm calling a script file from .net c#.
The Photoshop.ApplicationClass has a method DoJavaScriptFile which requires 3 parameters
1. string JavaScript file name
2. object arguments
3. object execution mode
If the object arguments are not parameters what are they?
And can you explain a bit more about using a file or stored variable from ASP environment?
Stephen
Copy link to clipboard
Copied
I believe you can use args in VB to get parameters, but not found a way in c#
To use a file or variables you need to write them out before calling the script, the script should have code to look for and read the file or variables.
Copy link to clipboard
Copied
Thanks
Do you please have any example code in .JSX that can read the web page that initiated the code as an object to find the variables?
Stephen
Copy link to clipboard
Copied
No, the variables would have to local, stored in Photoshop, or a local file.
You could use:
To set up as many variables as you like in Photoshop before calling the script.
string arg1 = "1st Parameter";
string Code = "$.setenv('arg1', '" + arg1 + "');";
app.DoJavaScript(Code, null, null);
example jsx
If($.getenv("arg1") == null){
alert("no variable in arg1");
}else{
alert($.getenv("arg1"));
}
Copy link to clipboard
Copied
Thanks, I'm sure your workaround would solve the problem and allow the objective be met of passing Parameters to the Jsx file.
However I persevered with getting the syntax correct on using the 2 parameter on DoJavaScriptFile(), namely the Arguments parameter.
The solution that works is as follows for anybody else finding themselves in the same situation;
string[] aArguments = new string[4] {"one", "two", "three", "four" } ;
var cArray = aArguments.Cast<object>().ToArray() ;
app.DoJavaScriptFile(cFile, cArray, 2); // 1 without debug, 2 for debug
In the .Jsx file, I used the arguments to retrieve values;
var cOption1 = arguments[0];
Again thanks for your workable solution.
Stephen
Copy link to clipboard
Copied
I find myself in the same boat you were in a few years ago.
trying to wrangle DoJavaScriptFile's second parameter.
I am trying to send a chunk of JSON data into extendscript for Photoshop.
I can single quote directly the whole thing and add to an array and get it to work, but when I pass a variable of that same data, something goes wrong and it doesn't pass through to Photoshop.
Something with escaping the quotes I guess? Similar to you, I am going through a bunch of different syntax, but I can't seem to figure this out.
I am trying in VBscript (inside some Powershell - if you know a way to do this all in Powershell, I am all ears. I gave up getting Powershell to "DoJavaScriptFile" for Photoshop)
thanks