-
1. Re: Passing a param to a JavaScript in Java using myApp.doScript
(Michael_Burbidge) Jul 15, 2008 12:56 PM (in response to (Jennifer_Cross))You are generally going about this correct. You don't show the code for creating the argSeq so I don't know what is in there.
I created the following script:
name = app.scriptArgs.get("name");
app.consoleout("Hello, " + name);
and then ran it using the following command line:
sampleclient -host localhost:5000 ~/Desktop/test.js name=mike -
2. Re: Passing a param to a JavaScript in Java using myApp.doScript
(Jennifer_Cross) Jul 15, 2008 1:24 PM (in response to (Jennifer_Cross))Mike,
Here's what I have in "argSeq".
String param1 = new String ("TestParam");
vtArgs[0] = VariableTypeUtils.createString(param1);
argSeq = OptArg.makeVariableTypeSeq(vtArgs);
In my JavaScript, I tried to retrieve the value using the following, but it doesn't work.
var myArg1 = app.scriptArgs.getValue ("param1");
Thanks again for your help.
Jennifer -
3. Re: Passing a param to a JavaScript in Java using myApp.doScript
(Michael_Burbidge) Jul 15, 2008 2:03 PM (in response to (Jennifer_Cross))Each argument should be a name, value pair. I think an array of 2. It looks like to me that the java code is not creating a name for each value.
It should probably be something like this:
String param1[2] = new String({"param1", "TestParam"});
... -
4. Re: Passing a param to a JavaScript in Java using myApp.doScript
(Jennifer_Cross) Jul 16, 2008 9:17 AM (in response to (Jennifer_Cross))Michael,
Thanks for your reply!
Jennifer -
5. Re: Passing a param to a JavaScript in Java using myApp.doScript
(SusanDoan) Jul 18, 2008 1:08 PM (in response to (Jennifer_Cross))There are two ways to access parameters passed to your script.
1) If your script is run by calling RunScript (via SOAP), parameters are stored in app.scriptArgs, and are passed to the script in an array of name/value pairs.
Called using SampleClient:
sampleclient -host localhost:12345 c:\myScript.jsx arg0=5
Accessing params in the script:
var myVal = app.scriptArgs.getValue("arg0");
2) If you are calling your script using doScript (via Scripting or Java), your parameters are accessed using the variable "arguments", and are passed to the script in a flat array.
Called from Java:
VariableType [] vtArgs = new VariableType[1];
vtArgs[0] = VariableTypeUtils.createString("5");
OptVariableTypeSeq argSeq = OptArg.makeVariableTypeSeq(vtArgs);
VariableType returnValue = myApp.doScript(
VariableTypeUtils.createFile("c:\myScript.jsx"),
OptArg.makeScriptLanguageEnum(kScriptLanguageJavascript.value),
argSeq,
OptArg.noUndoModesEnum(),
OptArg.noString());
Accessing params in the script:
var myVal = arguments[0];
Here is a script you can use to test where your parameters are stored (note that arguments is undefined if script is run via SOAP):
var myScriptArgs = "";
// replace "arg0" with the name of your parameter
if (app.scriptArgs.isDefined("arg0")) {
myScriptArgs = "arg0 = " + app.scriptArgs.getValue("arg0");
}
var myArguments = "";
for ( i = 0; i < arguments.length; i++) {
myArguments = myArguments + " arguments[" + i + "] = " + arguments[i];
}
var theResult = "ScriptArgs = " + myScriptArgs + " arguments = " + myArguments;
theResult; // returns value of theResult to caller -
6. Re: Passing a param to a JavaScript in Java using myApp.doScript
(Jennifer_Cross) Jul 18, 2008 1:42 PM (in response to (Jennifer_Cross))Susan,
Thanks for your response. I'm trying to do what you describe in item 2; however, my main problem is I do not know how to specify the name of the parameter in my Java class in order to use it to retrieve the value of the param in my JavaScript. For example, you say to replace arg0 with the name of my parameter. My question is I don't know how to give it a name in the Java class before passing it to the JavaScript via doScript. I'm probably missing something!
Thanks,
Jennifer -
7. Re: Passing a param to a JavaScript in Java using myApp.doScript
(SusanDoan) Jul 21, 2008 9:48 AM (in response to (Jennifer_Cross))When calling a script from Java using doScript, your parameters are sent in an array of values - no names are associated with the parameters. To access the parameters in your script, you access the "arguments" array like this:
var arg0 = arguments[0];
var arg1 = arguments[1];
You probably need to rewrite your script to use the "arguments" array instead of scriptArgs.
Susan -
8. Re: Passing a param to a JavaScript in Java using myApp.doScript
sivaciti Jul 5, 2011 10:32 PM (in response to (Jennifer_Cross))When i am running the following code i am getting the exception as
com.adobe.ids.IdsException: IDL:com/adobe/ids/IdsException:1.0
VariableType[] vtArgs = new VariableType[1];
vtArgs[0] = VariableTypeUtils.createString("5");
OptVariableTypeSeq argSeq = OptArg.makeVariableTypeSeq(vtArgs);
if (myApp != null) {
try {
myApp.doScript(
VariableTypeUtils.createFile("C:/Program Files/Adobe/Adobe InDesign CS5.5/Scripts/Scripts Panel/Samples/JavaScript/CreateImage.jsx"),
OptArg.makeScriptLanguageEnum(kScriptLanguageJavascript.value),
argSeq,
OptArg.noUndoModesEnum(),
OptArg.noString());
}
catch (IdsException exc) {
System.err.println("Exception #" + exc.errorCode + ": "
+ exc.errorMsg);
exc.printStackTrace();
}
Please solve my problem
Thanks,
Siva
-
9. Re: Passing a param to a JavaScript in Java using myApp.doScript
hxkris-dev Jan 24, 2012 5:49 AM (in response to (SusanDoan))Susan, this doesn't work. I have the same problem. described here http://forums.adobe.com/thread/953607?tstart=0.
Problem seems to be trivial, but nobody can give us right answer...
Please help.
K.